public static List<String> getBetweenDates(Date begin, Date end) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
List<String> result = new ArrayList<>();
Calendar tempStart = Calendar.getInstance();
tempStart.setTime(begin);
//注释打开,不包含开始日期
// Calendar tempEnd = Calendar.getInstance();
// tempStart.add(Calendar.DAY_OF_YEAR, 1);
// tempEnd.setTime(end);
// while (tempStart.before(tempEnd)) {
// result.add(format.format(tempStart.getTime()));
// tempStart.add(Calendar.DAY_OF_YEAR, 1);
// }
while(begin.getTime()<=end.getTime()){
result.add(format.format(tempStart.getTime()));
tempStart.add(Calendar.DAY_OF_YEAR, 1);
begin = tempStart.getTime();
}
return result;
}
两日期之间时间段日期集合
最新推荐文章于 2022-04-07 18:13:14 发布