问题
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