我知道。转换后的java的between()。util。日期
这有效(返回0):
ChronoUnit.SECONDS.between(
LocalDateTime.now(),
LocalDateTime.now());
这失败了:
ChronoUnit.SECONDS.between(
ZonedDateTime.ofInstant(new Date().toInstant(), ZoneId.of("UTC"),
LocalDateTime.now());
除此之外:
Exception in thread "main" java.time.DateTimeException: Unable to obtain ZonedDateTime from TemporalAccessor: 2016-10-27T14:05:37.617 of type java.time.LocalDateTime
...
Caused by: java.time.DateTimeException: Unable to obtain ZoneId from TemporalAccessor: 2016-10-27T14:05:37.617 of type java.time.LocalDateTime
at java.time.ZoneId.from(ZoneId.java:466)
at java.time.ZonedDateTime.from(ZonedDateTime.java:553)
... 3 more
有人知道我如何使用java吗。util。用一种时辰约会。在()之间
# 1 楼答案
LocalDateTime没有时区。无法将其与表示精确时间点的瞬间或分区DateTime进行比较
因为你的问题是关于比较一个日期,最简单的方法是比较一个瞬间和一个瞬间: