获取一个月内有的日期
- 指定格式为“yyyy-MM-dd”
- 以当前月的某一天为基础
点击查看代码
@Test
public void test4() {
LocalDate start = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
LocalDate end = LocalDate.now().with(TemporalAdjusters.lastDayOfMonth());
long days = Duration.between(start.atStartOfDay(), end.atStartOfDay()).toDays();
List<String> lst = new ArrayList<>();
for (int i = 0; i <= days; i++) {
lst.add(start.plusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
}
lst.forEach(System.out::println);
}