java8使用时间计算

 public static void main(String[] args) {
        LocalDate localDate = LocalDate.now();
        //1.获取周日
        LocalDate with = localDate.with(DayOfWeek.SUNDAY);
        System.out.println(with);
        //2.获取本月最后一天
        with = localDate.with(TemporalAdjusters.lastDayOfMonth());
        System.out.println(with);
        //3.获取本月上一个周三
        TemporalAdjuster temporalAdjuster = TemporalAdjusters.nextOrSame(DayOfWeek.WEDNESDAY);


        with = with.with(TemporalAdjusters.previousOrSame(DayOfWeek.WEDNESDAY));
        System.out.println(with);
        //4.下一个周日
        with = localDate.with(TemporalAdjusters.next(DayOfWeek.WEDNESDAY)); //(不含今天)
        System.out.println(with);


        System.out.println(DayOfWeek.valueOf("WEDNESDAY"));


        String windowsName = getWindowsName(localDate);
        System.out.println(windowsName);

        System.out.println(localDate.with(TemporalAdjusters.lastInMonth(DayOfWeek.WEDNESDAY)));

        System.out.println(7 % 14);
        System.out.println(0 % 14);
    }

 

posted on 2024-02-01 14:27  张释文  阅读(21)  评论(0编辑  收藏  举报