Java OffsetDateTime showing strange year value [duplicate]

霸气de小男生 提交于 2020-12-15 11:04:32

问题


Per the IntelliJ debugger, the OffsetDateTime value is showing like:

+51434-04-02T15:28:41Z

Any idea how to parse the year part or make sense of it? The raw date is actually in milliseconds when I view it on the DB. I have no access to the team that is saving these dates. Also, when accessing the data via my tests it's showing the same when I do a log.debug.


回答1:


Seeing the timestamp, I think I know why this is happening. Some part of the code has incorrectly interpreted the timestamp 1559909381182. This timestamp represents a the number of milliseconds since the epoch, but your code has interpreted it as a number of seconds. Compare these two lines:

System.out.println(Instant.ofEpochSecond(1559909381182L));
System.out.println(Instant.ofEpochMilli(1559909381182L));

The first will print out a date thousands of years in the future, while the second line will print a more reasonable date.

You should try and find where you have interpreted it as a second.



来源:https://stackoverflow.com/questions/60287533/java-offsetdatetime-showing-strange-year-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!