Mapping Date to Instant adds a week

Viewed 47

I have the following object of type java.util.Date (Java 8):

enter image description here

So basically 1 January 1235 in CET format. But the moment I cast this with Instant:

enter image description here

IntelliJ show me that a whole week has been added! Instant uses UTC format, which explains why one hour is subtracted (one hour difference between CET and UTC). But where does the week come from?

1 Answers

That's because most of humanity was using Julian calendar in 1235, and has switched to Gregorian since.

Old style Java Dates do a best effort to account for this when it can deduce for a Locale when it did the switch from Julian to Calendar.

When these switches were made, the date in these countries switched to a different place on the calendar, making it look like the date just skipped a bunch of days.

The newer java.time.* system ignores the historic existence of Julian calendars and is ill-suited to represent time gaps in historic dates.

Related