牧码

时间不多,道路很长

打印昨天的当前时刻

方式一:通过Calendar实现

Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE,-1);
System.out.println(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(cal.getTime()));

方式二:通过Date实现

// 1天的时间 = 24小时 x 60分钟 x 60秒 x 1000毫秒 单位是L
Date yesterday = new Date(new Date().getTime() - 24 * 60 * 60 * 1000);
System.out.println(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(yesterday));
posted @ 2019-01-04 16:16  脚印在泥泞路上  阅读(147)  评论(0编辑  收藏  举报