LocalDateTime dateTime = LocalDateTime
.ofInstant(Instant.ofEpochMilli(1528197133157L), ZoneId.systemDefault());
LocalDate now = LocalDate.now();
Period between = Period.between(dateTime.toLocalDate(), now);
long between1 = ChronoUnit.DAYS.between(dateTime.toLocalDate(), now);
long between2 = ChronoUnit.MONTHS.between(dateTime.toLocalDate(), now);
使用Period的话有坑
.

需要替换为

String 类型转localDate
LocalDate beginDateTime = LocalDate.parse(beginDate, DateTimeFormatter.ofPattern(“yyyy-MM-dd”));
date类型转localDate
Date dates = new SimpleDateFormat(“yyyyMM”).parse(cycle);
Instant instant = dates.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
LocalDate localDate = instant.atZone(zoneId).toLocalDate();
转载来自
https://blog.csdn.net/fcfwang_net/article/details/86106617
https://blog.csdn.net/wanzhix/article/details/78922752
https://blog.csdn.net/xielaixiaohun/article/details/78424338
本文详细介绍了如何在Java中使用LocalDateTime、LocalDate和ChronoUnit进行日期时间的转换和计算,包括从字符串和日期类型转换到LocalDate的方法,以及计算两个日期之间的差值。

1923

被折叠的 条评论
为什么被折叠?



