获取一个月内有的日期

  1. 指定格式为“yyyy-MM-dd”
  2. 以当前月的某一天为基础
点击查看代码
@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);
    }
posted @ 2022-09-19 09:00  normalpers  阅读(20)  评论(0编辑  收藏  举报