jdk8 计算两个时间段间隔天数,月,年

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDate startDate = LocalDate.parse(startTime, formatter);
LocalDate endDate = LocalDate.parse(endTime, formatter);
// 日期区间
long days = ChronoUnit.DAYS.between(startDate, endDate);
//月
long month = ChronoUnit.MONTHS.between(startDate, endDate);
//年
long year = ChronoUnit.YEARS.between(startDate, endDate);

更多用法见官网

    原文作者:Valin0927
    原文地址: https://blog.csdn.net/qq_29896935/article/details/90768861
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞