某些场景知道某个日期,需要知道这个日期所在月份的所有日期,使用LocalDate非常方便,
上代码:
LocalDate time = LocalDate.parse("2023-07-03", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
///time.atStartOfDay();
LocalDate st = time.with(TemporalAdjusters.firstDayOfMonth());
LocalDate et = time.with(TemporalAdjusters.lastDayOfMonth());
List<LocalDate> list = new ArrayList<>();
while (st.isBefore(et)){
list.add(LocalDate.parse(st.toString(),DateTimeFormatter.ofPattern("yyyy-MM-dd")));
st = st.plusDays(1);
}
list.add(et);
list.forEach(System.out::println);