lambda表达式得出2个yyyy-MM-dd日期间的所有日期

 LocalDateTime now = LocalDateTime.now();
        final LocalDateTime yuandan ;
        //如果当前日期在12/1之前 则生成当年的天数
        if(now.isBefore(LocalDateTime.of(now.getYear() , 5, 1, 0, 0))) {
            yuandan = LocalDateTime.of(now.getYear(), 1, 1, 0, 0);
        }
        else{
            yuandan = LocalDateTime.of(now.getYear() +1, 1, 1, 0, 0);
        }
        //遍历 判断闰年
        EveryDayType e1 = new EveryDayType();
        IntStream.iterate(0, o->o+1).limit(Year.isLeap(yuandan.getYear()) ? 366:365).
                mapToObj(v->formatTime(yuandan.plusDays(v), "yyyy-MM-dd")).forEach(i ->{
            LocalDate date = LocalDate.parse(i);
           System.out.println(date);
           
          
        });
发布了16 篇原创文章 · 获赞 0 · 访问量 207

猜你喜欢

转载自blog.csdn.net/Jeremz/article/details/104394512
今日推荐