如何使用java8 time API获得一个月的两个特定日期之间的所有周末?

LocalDate startDate = LocalDate.of(2018, 10, 26);
LocalDate endDate = LocalDate.of(2018, 11, 27);
while (startDate.isBefore(endDate)) {
    if (startDate.getDayOfWeek().equals(DayOfWeek.SATURDAY) || startDate.getDayOfWeek().equals(DayOfWeek.SUNDAY)) {
        System.out.println(startDate + ":" + startDate.getDayOfWeek());
    }
    startDate = startDate.plusDays(1);
}

 

posted @ 2022-11-21 19:55  锐洋智能  阅读(326)  评论(0编辑  收藏  举报