Search code examples
javalocaldate

Converting past gregorianCalendar date with timezone to localDate return bad time


When I am converting GregorianCalendar to LocalDate I have this problem:

System.out.println(((GregorianCalendar) DatatypeConverter.parseDateTime("1945-10-01+02:00")).toZonedDateTime()
        .withZoneSameInstant(ZoneId.systemDefault()).toLocalDate());

return 1945-10-01 what is OK

    System.out.println(((GregorianCalendar) DatatypeConverter.parseDateTime("1945-10-02+02:00")).toZonedDateTime()
            .withZoneSameInstant(ZoneId.systemDefault()).toLocalDate());

return same date: 1945-10-01 what is NOT OK

Why ?

My timezone ist Prague. When I check this side +2h should be till 18.11 not till 10.1


Solution

  • Java Time API relies on IANA Time Zone Database. According to it, time shift had happened on 10.1:

    Rule    Czech   1945    only    -   Oct  1  2:00s   0   -