【发布时间】:2021-03-05 15:09:54
【问题描述】:
我将 Instant 转换为 LocalDate,这是我的实现:
theInstant.atZone(ZoneId.systemDefault()).toLocalDate();
但是,我在 Junit 测试中遇到了异常: java.time.DateTimeException:年的值无效(有效值-999999999 - 999999999):-1000000000
谁能帮忙?
谢谢!
【问题讨论】:
-
您是如何创建
Instant的?也可以在这里看到 JUnit 测试...此外,您已将Instant转换为ZonedDateTime通过.atZone(...)然后通过.toLocalDate()提取日期部分。 -
这种重现错误
Instant.MIN.atZone(ZoneId.systemDefault()); -
atZone 方法描述为
An exception will be thrown if the instant is toolarge to fit into a zoned date-time. -
帮助我们为您提供帮助。
theInstant包含什么? -
还有 10 亿年前的瞬间有什么意义?
标签: java junit java-time localdate java.time.instant