public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd 00:00:00");//定义时间格式
Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.add(Calendar.DATE, - 8);
System.out.println("前一周时间》》》》》》》》》》"+sdf.format(c.getTime()));
c.setTime(new Date());
c.add(Calendar.DATE, - 1);
System.out.println("前一天时间》》》》》》》》》》"+sdf.format(c.getTime()));
}
当前时间为:2017-6-2 17:01:48
运行结果:
Paste_Image.png
网友评论