java8 利用java7的date 做一个开始日期到结束日期 计算中间一共隔了多少日期

public static List<LocalDate> getDiffdate(String date) {
        List<LocalDate> lDate = new ArrayList<>();
        LocalDate firstDate = LocalDate.now();
        LocalDate startDate = LocalDate.parse(date);
        Calendar calBegin = Calendar.getInstance();
        ZoneId zone = ZoneId.systemDefault();
        Instant instant = startDate.atStartOfDay(zone).toInstant();
        Date strDate = Date.from(instant);
        calBegin.setTime(strDate);
        Calendar calEnd = Calendar.getInstance();
        Instant tinstant = firstDate.atStartOfDay(zone).toInstant();
        Date endDate = Date.from(tinstant);
        calEnd.setTime(endDate);
        lDate.add(startDate);
        while (endDate.after(calBegin.getTime())) {
            calBegin.add(Calendar.DAY_OF_MONTH, 1);
            Date dates = calBegin.getTime();
            Instant intoLocdate = dates.toInstant();
            LocalDateTime localDateTime = LocalDateTime.ofInstant(intoLocdate,
                    zone);
            LocalDate localDate = localDateTime.toLocalDate();
            lDate.add(localDate);
        }
        return lDate;

    }                                 也不咋懂java8的时间, 大概就是 利用java8以下的版本计算的时间,然后转成Localdate了

你可能感兴趣的:(java)