将 java.util.Date 转换为 org.joda.time.LocalDateTime 时出现问题
import org.joda.time.LocalDateTime;
import java.util.Date;
使用此日期或以下日期都可以:
new LocalDateTime(new Date(0,0,1,2,30))
— 1900-01-01T02:30:00.000new LocalDateTime(new Date(111,4,24,19,51))
— 2011-05-24T19:51:00.000
但是前面的日期有些难以理解:
new LocalDateTime(new Date(0, 0,1,2,29,50))
— 1900-01-01T01:59:50.000new LocalDateTime(new Date(0,0,1))
— 1899-12- 31T23:30:00.000新 LocalDateTime(新日期(-50,0,1))
— 1849-12-31T23:30:20.000新 LocalDateTime(新日期(-116,6, 4))
— 1784-07-03T23:30:20.000
谁知道这是什么,以及如何防止这个问题?
import org.joda.time.LocalDateTime;
import java.util.Date;
With this date or with the following ones it's all OK:
new LocalDateTime(new Date(0,0,1,2,30))
— 1900-01-01T02:30:00.000new LocalDateTime(new Date(111,4,24,19,51))
— 2011-05-24T19:51:00.000
But there is something incomprehensible with preceding dates:
new LocalDateTime(new Date(0,0,1,2,29,50))
— 1900-01-01T01:59:50.000new LocalDateTime(new Date(0,0,1))
— 1899-12-31T23:30:00.000new LocalDateTime(new Date(-50,0,1))
— 1849-12-31T23:30:20.000new LocalDateTime(new Date(-116,6,4))
— 1784-07-03T23:30:20.000
Who knows, what is this, and how to prevent this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用哪个时区?您似乎正在处理时钟不连续性,可能是1900 年 1 月 1 日凌晨 2 点左右。这意味着当地时钟跳过了一定的时间,并且正式不存在。这也可能是夏令时的变化。最后 3 行中的一致差异看起来很奇怪 - 也许 Java 的日历和 Joda Time 使用不同版本的时区数据库,并且其中之一缺少更改。
您可以在链接到的网站上检查您的时区是否发生变化。
Which timezone are you using? It looks like you're dealing with a clock discontinuity, possibly around 2 AM on January 1st, 1900. That means a certain amount of time was skipped by the local clock and officially doesn't exist. It could also be a change in DST. The consistent difference in your last 3 lines looks strange though - perhaps Java's Calendar and Joda Time use a different version of the timezone database and the change is missing in one of them.
You can check your timezone for changes at the linked-to site.