SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String[] days= new String[10];
for (int i = 0; i <10; i++) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, i);
days[i]=sdf.format(calendar.getTime());
System.out.println(sdf.format(calendar.getTime()));;
}
System.out.println(days.length);
效果如图:
sql:
SELECT date(create_time) FROM tb_person where DATE_SUB(CURDATE(), INTERVAL 3 DAY) <= date(create_time)
获取前七天日期: