SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar c = Calendar.getInstance();
//过去七天
c.setTime(new Date());
c.add(Calendar.DATE, - 7);
Date d = c.getTime();
String day = format.format(d);
System.out.println("过去七天:"+day);
过去七天:2020-01-07 18:08:28
用某个时间减去当前时间的前一周时间,查看时间距离前一周是否够一周
Date d1 = format.parse(day);
Date d2 = format.parse("2020-01-14 18:23:56");
//数据的时间减去七天前的时间小于等于0的话说明时间差大于7天
long diff = d2.getTime()-d1.getTime();//这样得到的差值是微秒级别
// long days = diff / (1000 * 60 * 60 * 24);
long days = diff / (1000);
long hours = (diff-days*(1000 * 60 * 60 * 24))/(1000* 60 * 60);
long minutes = (diff-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60))/(1000* 60);
System.out.println(days);