java日期,时间戳相关应用

DateFormat, SimpleDateFormat类是规定时间格式的模板,可以将时间戳或者Date对象转化为规定的时间格式

DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

df.format(new Date());

当前日期的前一天和当前日期的后一天

Calendar cd = Calendar.getInstance();

cd.setTime(currentDate);

cd.add(Calendar.DAY_OF_MONTH, -1);

preMonthDate = cd.getTime();

获取时间戳

long time = preMonthDate.getTime();

猜你喜欢

转载自blog.csdn.net/liangtianmeng/article/details/77076164