Java OffsetDateTime显示奇怪的年份值 [英] Java OffsetDateTime showing strange year value

查看:53
本文介绍了Java OffsetDateTime显示奇怪的年份值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据IntelliJ调试器,OffsetDateTime值显示如下:

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

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

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

有什么主意如何解析年份部分或使之有意义吗?当我在数据库上查看原始日期时,原始日期实际上是以毫秒为单位.我无法访问保存这些日期的团队.另外,通过测试访问数据时,执行log.debug时也显示相同的结果.

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.

推荐答案

看到时间戳,我想我知道为什么会这样.代码的某些部分错误地解释了时间戳1559909381182.此时间戳表示自时期以来的毫秒数,但是您的代码已将其解释为 seconds 的数目.比较这两行:

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.

这篇关于Java OffsetDateTime显示奇怪的年份值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆