java日期,时间戳相关应用

来源:互联网 发布:淘宝买家秀招聘 编辑:程序博客网 时间:2024/05/12 07:45

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();

原创粉丝点击