private static Date getDateAdd(int days){
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.add(Calendar.DAY_OF_MONTH, -days);
return c.getTime();
}
private static List<String> getDaysBetwwen(int days){ //最近几天日期
List<String> dayss = new ArrayList<>();
Calendar start = Calendar.getInstance();
start.setTime(getDateAdd(days));
Long startTIme = start.getTimeInMillis();
Calendar end = Calendar.getInstance();
end.setTime(new Date());
Long endTime = end.getTimeInMillis();
Long oneDay = 1000 * 60 * 60 * 24l;
Long time = startTIme;
while (time <= endTime) {
Date d = new Date(time);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(df.format(d));
dayss.add(df.format(d));
time += oneDay;
}
return dayss;
}

相关文章:

  • 2022-12-23
  • 2021-12-20
  • 2021-10-11
  • 2022-12-23
  • 2021-05-25
  • 2022-12-23
  • 2022-01-15
猜你喜欢
  • 2021-11-03
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2021-10-15
  • 2022-01-31
  • 2022-12-23
相关资源
相似解决方案