简体   繁体   English

DateTime给出了意想不到的结果

[英]DateTime is giving unexpected result

I have tried this using Jodatime DateTime , 我用Jodatime DateTime试过这个,

    DateTime dateTime = DateTime
            .parse("1-JAN-1900", DateTimeFormat.forPattern("dd-MMM-yyyy"))
            .plusSeconds(2075866000);
    String dateTimeStr = DateTimeFormat.forPattern(
            "yyyy/MM/dd HH:mm:ss").print(dateTime);
    System.out.println(dateTimeStr);

I have also tried using Jodatime MutableDateTime 我也尝试过使用Jodatime MutableDateTime

    MutableDateTime dateTime = MutableDateTime
            .parse("1-JAN-1900", DateTimeFormat.forPattern("dd-MMM-yyyy"));
    dateTime.add(DurationFieldType.seconds(), 2075866000);
    String dateTimeStr = DateTimeFormat.forPattern(
                "yyyy/MM/dd HH:mm:ss").print(dateTime.toDateTime());
    System.out.println(dateTimeStr);

Both are giving me the same result, 1965/10/13 06:09:54 . 两者都给了我相同的结果, 1965/10/13 06:09:54

I expect, 1965/10/13 05:26:40 , instead. 我期待, 1965/10/13 05:26:40 ,相反。 I'm getting this using Oracle query given below, 我使用下面给出的Oracle查询得到了这个,

select to_date('1900-JAN-1') + 2075866000/86400 from dual

And upon contradiction between Joda and Oracle, I tried Wolframalpha , that is also giving me the same result as Oracle. 在Joda和Oracle之间发生矛盾之后,我尝试了Wolframalpha ,这也给了我与Oracle相同的结果。

Anyone please explain why is that difference? 有人请解释为什么会有这种差异?

According to timeanddate.com there were timezone adjustments in Kuala Lumpur in 1901, 1905, 1933, 1941, 1942, 1945, the sum total of which probably explains the discrepancy you're seeing. 根据timeanddate.com ,吉隆坡在1901年,1905年,1933年,1941年,1942年,1945年进行了时区调整,总和可能解释了你所看到的差异。

Edit: In fact, if you add up all the adjustments you get 43:14, which is exactly the discrepancy you're seeing. 编辑:事实上,如果你把所有调整加起来你得到43:14,这正是你所看到的差异。

JodaTime and Java are giving you the correct numbers. JodaTime和Java正在为您提供正确的数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM