gpt4 book ai didi

Java 科学数据处理

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:47:02 25 4
gpt4 key购买 nike

我的问题是当我们想要存储从地球诞生到地球尽头的日期时应该如何处理日期(预计在 100000000000000000000-12-31 23:59:00.0000 +1 ).

我相信一些科学家拥有像这样的 Dates 库。自 Joda-Time还使用 long 作为内部存储,它超出了范围。从头开始开发日历可能很困难,因为我们必须处理所有特殊情况,例如从儒略历切换到公历和闰年/秒......

最佳答案

JSR-310 - Java 8 中新的日期/时间 API - 已经处理了这个问题。来自Instant docs :

For practicality, the instant is stored with some constraints. The measurable time-line is restricted to the number of seconds that can be held in a long. This is greater than the current estimated age of the universe. The instant is stored to nanosecond resolution.

有一个backport to Java 7 , 如果你等不及 Java 8 的发布了:)

但是,JSR-310 可能不会按照您希望的方式处理闰秒。基本上它试图(完全合理地)通过坚持提供的任何时钟执行拖尾来从系统中删除闰秒。 (所以数据模型中没有表示闰秒。)您需要小心处理。当然,遥远 future 的日期使得闰秒计算变得不可能,而且几乎肯定是微不足道的:)

编辑:正如下面的答案所指出的,上面的引用实际上是一个规范错误,Instant 将“仅”支持高达 10 亿的年份值。

关于Java 科学数据处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21829477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com