简体   繁体   中英

DateTime is giving unexpected result

I have tried this using 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

    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 .

I expect, 1965/10/13 05:26:40 , instead. I'm getting this using Oracle query given below,

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.

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.

Edit: In fact, if you add up all the adjustments you get 43:14, which is exactly the discrepancy you're seeing.

JodaTime and Java are giving you the correct numbers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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