是否可以在新java.timeAPI中获取两个日期之间的所有日期?
假设我有这部分代码:
@Test
public void testGenerateChartCalendarData() {
LocalDate startDate = LocalDate.now();
LocalDate endDate = startDate.plusMonths(1);
endDate = endDate.withDayOfMonth(endDate.lengthOfMonth());
}
Run Code Online (Sandbox Code Playgroud)
现在我需要startDate和之间的所有日期endDate.
我想要得到daysBetween两个日期并迭代:
long daysBetween = ChronoUnit.DAYS.between(startDate, endDate);
for(int i = 0; i <= daysBetween; i++){
startDate.plusDays(i); //...do the stuff with the new date...
}
Run Code Online (Sandbox Code Playgroud)
有更好的方法来获取日期吗?