LocalDate获取指定月的上个月的第一天和最后一天
LocalDate date = LocalDate.of(2022, 8, 30);
LocalDate lastMonth = date.minusMonths(1); // 当前月份减1
LocalDate firstDay = lastMonth.with(TemporalAdjusters.firstDayOfMonth()); // 获取当前月的第一天
LocalDate lastDay = lastMonth.with(TemporalAdjusters.lastDayOfMonth()); // 获取当前月的最后一天
System.out.println(date);
System.out.println(lastMonth);
System.out.println(firstDay);
System.out.println(lastDay);
输出结果:
2022-08-30
2022-07-30
2022-07-01
2022-07-31