The difference between JodaTime and the calendar for the years before 1900

I get different values ​​in milliseconds for the same date in the past using JodaTime lib and java.util.Calendar. For example, for the first year of AD

void test() {
    int year = 1;
    DateTime dt = new DateTime(year, 1,1,0,0,0,0);
    dt = dt.toDateTime(GregorianChronology.getInstance());

    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(year, 0, 1, 0, 0, 0);

    DateTime endDate = new DateTime(cal.getTimeInMillis());
    endDate = endDate.toDateTime(GregorianChronology.getInstance());

    System.out.println("JodaTime: " + dt);
    System.out.println("JodaTime, ms: " + dt.getMillis());
    System.out.println("Calendar: " + cal.getTime());
    System.out.println("Calendar, ms: " + cal.getTimeInMillis());
    System.out.println("JodaTime by Calendar: " + endDate);
}

By default, DateTime uses ISOChronology, and Calendar uses GregorianCalendar (except for TH and JA places). Therefore, I set the Gregorian chronology, but nothing has changed. The result of the execution is

JodaTime:       0001-01-01T00:00:00.000+01:34:52
JodaTime, ms:   -62135602492000
Calendar:       Sat Jan 01 00:00:00 EET 1
Calendar, ms:   -62135776800000
JodaTime by Calendar:   0000-12-29T23:34:52.000+01:34:52

Can anyone suggest that I'm something wrong?

+3
source share
2 answers

After several tests, I found out the following:

  • , , Europe/Athens. Atm 2 , 1916 1:34:52 ( ). =). 1582 1916 ( 1900, ) , 1582-10-15 Sun Calendar Joda Time ( UTC)

  • 1582-10-14, java.util.Calendar(cal.set(1582, 9, 14, 0, 0, 0);), Sun Oct 24 00: 00: 00 EET 1582 ( ). 05-14.10.1582. 1582-10-05 , . - . 3- . ,

+2

, . UTC, .

(, ) "" .

, zoneinfo , / 1:34:52 1916 ( LMT AMT 1895 ).

1:50:16 1880 .

, Java , ?

+4

Source: https://habr.com/ru/post/1785194/


All Articles