Java 8 LocalDate - How do I get all dates between two dates?

前端 未结 8 2002
陌清茗
陌清茗 2020-12-03 00:10

Is there a usablility to get all dates between two dates in the new java.time API?

Let\'s say I have this part of code:



        
8条回答
  •  生来不讨喜
    2020-12-03 00:49

    The ThreeTen-Extra library has a LocalDateRange class that can do exactly what you're requesting:

    LocalDateRange.ofClosed(startDate, endDate).stream()
            .forEach(/* ...do the stuff with the new date... */);
    

提交回复
热议问题