LocalDateTime now = LocalDateTime.of(2022,12,31,0,1,1);
WeekFields weekFields = WeekFields.of(DayOfWeek.FRIDAY,1);
int dayOfWeek = now.getDayOfWeek().get(weekFields.dayOfWeek());
System.out.println("日期: "+ LocalDateTimeUtil.format(now, DatePattern.NORM_DATETIME_PATTERN));
System.out.println("第几周weekOfYear: "+now.get(weekFields.weekOfYear()));
System.out.println("第几周weekOfWeekBasedYear: "+now.get(weekFields.weekOfWeekBasedYear()));
System.out.println("本周的第几天(从1开始): "+dayOfWeek);
System.out.println("本周的开始日期: "+now.minusDays(dayOfWeek - 1));
System.out.println();
now = now.plusDays(1);
dayOfWeek = now.getDayOfWeek().get(weekFields.dayOfWeek());
System.out.println("加一天日期: "+ LocalDateTimeUtil.format(now, DatePattern.NORM_DATETIME_PATTERN));
System.out.println("第几周weekOfYear: "+now.get(weekFields.weekOfYear()));
System.out.println("第几周weekOfWeekBasedYear: "+now.get(weekFields.weekOfYear()));
System.out.println("本周的第几天(从1开始): "+dayOfWeek);
System.out.println("本周的开始日期: "+now.minusDays(dayOfWeek - 1));
System.out.println();
now = now.plusWeeks(1);
dayOfWeek = now.getDayOfWeek().get(weekFields.dayOfWeek());
System.out.println("加一周日期: "+ LocalDateTimeUtil.format(now, DatePattern.NORM_DATETIME_PATTERN));
System.out.println("第几周weekOfYear: "+now.get(weekFields.weekOfYear()));
System.out.println("第几周weekOfWeekBasedYear: "+now.get(weekFields.weekOfYear()));
System.out.println("本周的第几天(从1开始): "+dayOfWeek);
System.out.println("本周的开始日期: "+now.minusDays(dayOfWeek - 1));
标签:dayOfWeek,自定义,System,JDK8,LocalDateTime,println,weekFields,now,out
From: https://www.cnblogs.com/Zhusi/p/17652439.html