获取两个日期之间的所有日期列表
public static void time(String startTime, String endTime){
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate startDate = LocalDate.parse(startTime, fmt);
LocalDate endDate = LocalDate.parse(endTime, fmt);
long numOfDays = ChronoUnit.DAYS.between(startDate, endDate);
List<LocalDate> listOfDates = Stream.iterate(startDate, date -> date.plusDays(1))
.limit(numOfDays)
.collect(Collectors.toList());
listOfDates.forEach(item->{
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
System.out.println(dateTimeFormatter.format(item));
});
}
public static void main(String[] args) {
time("2021-06-02","2021-06-05");
}