Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 482
Adeel Ansari Avatar asked May 28 '12 04:05

Adeel Ansari


1 Answers

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.

like image 140
Jim Garrison Avatar answered Sep 22 '22 13:09

Jim Garrison