System.out.println("---------------------");
LocalDate currentDate = LocalDate.now();
DateTimeFormatter nowFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String nowDate = currentDate.format(nowFormatter);
System.out.println("当前:"+nowDate);
LocalDate futureDate = currentDate.plusDays(30);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String formattedDate1 = futureDate.format(formatter);
System.out.println("30天后:"+formattedDate1);
LocalDate pastDate = currentDate.minusDays(30);
String formattedDate2 = pastDate.format(formatter);
System.out.println("30天前:"+formattedDate2);
System.out.println("---------------------");
System.out.println("---------------------");
LocalDate currentDate = LocalDate.now();
if (currentDate.getDayOfWeek() == DayOfWeek.FRIDAY) {
LocalDate monday = currentDate.with(TemporalAdjusters.previous(DayOfWeek.MONDAY));
LocalDate tuesday = monday.plusDays(1);
LocalDate wednesday = tuesday.plusDays(1);
LocalDate thursday = wednesday.plusDays(1);
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
System.out.println("本周一:" + monday.format(timeFormatter));
System.out.println("本周二:" + tuesday.format(timeFormatter));
System.out.println("本周三:" + wednesday.format(timeFormatter));
System.out.println("本周四:" + thursday.format(timeFormatter));
System.out.println("本周五:" + currentDate.format(timeFormatter));
}
LocalDate currentDate = LocalDate.now();
if (currentDate.getDayOfWeek() != DayOfWeek.FRIDAY) {
LocalDate friday = currentDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.FRIDAY));
currentDate = friday;
}
LocalDate monday = currentDate.with(TemporalAdjusters.previous(DayOfWeek.MONDAY));
LocalDate tuesday = monday.plusDays(1);
LocalDate wednesday = tuesday.plusDays(1);
LocalDate thursday = wednesday.plusDays(1);
DateTimeFormatter formatter3 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
System.out.println("本周一:" + monday.format(formatter3));
System.out.println("本周二:" + tuesday.format(formatter3));
System.out.println("本周三:" + wednesday.format(formatter3));
System.out.println("本周四:" + thursday.format(formatter3));
System.out.println("本周五:" + currentDate.format(formatter3));
---------------------
当前:2024-01-17
30天后:2024-02-16
30天前:2023-12-18
---------------------
本周一:2024-01-15
本周二:2024-01-16
本周三:2024-01-17
本周四:2024-01-18
本周五:2024-01-19