Java8求本月每周末的日期

public static void main(String[] args) {
        LocalDate today = LocalDate.now();
       //本月每周日的日期
        //本月的第一天
        LocalDate firstday = LocalDate.of(today.getYear(),today.getMonth(),1);
        //本月的最后一天
        LocalDate lastDay =today.with(TemporalAdjusters.lastDayOfMonth());
        //最后一天的那天是本周的第几周
        int weeks = lastDay.get(ChronoField.ALIGNED_WEEK_OF_MONTH);
        int i=1;
        //第一周的星期天
        LocalDate weekDate =firstday.with(TemporalAdjusters.next(DayOfWeek.SUNDAY));
        while (i<weeks){
            System.out.println("第"+i+"周的周末是:"+weekDate+" ");
            weekDate = weekDate.with(TemporalAdjusters.next(DayOfWeek.SUNDAY));
            i++;
        }
    }
    原文作者:红土豆_jie
    原文地址: https://blog.csdn.net/u010031939/article/details/53908568
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞