java8 LocalDate 获取一段时间的每一天的日期

    /**
     * 获取一段时间的每一天日期
     *
     * @param start
     * @param end
     * @return
     * @throws Exception
     */

    public static List getBetweenDate(String start, String end) {
        List list = new ArrayList<>();
        LocalDate startDate = LocalDate.parse(start);
        LocalDate endDate = LocalDate.parse(end);
        long distance = ChronoUnit.DAYS.between(startDate, endDate);
        if (distance < 1) {
            return list;
        }
        Stream.iterate(startDate, d -> d.plusDays(1)).limit(distance + 1).forEach(f -> list.add(f.toString()));
        return list;
    }

//调用  List betweenDate = getBetweenDate("2019-02-01", "2019-05-31");

 

你可能感兴趣的:(java,笔记)