G
G
glorfindeil2016-05-25 16:13:42
Java
glorfindeil, 2016-05-25 16:13:42

Why are the resulting values ​​so different when converting java.util.Date to Instant?

log.debug("Date is " + date);
           Instant instant = date.toInstant();
           log.debug("Instant date is " + instant);
           LocalDateTime localTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());


2016-05-25-15:57:16.729 DEBUG|G|rrcsdDocGeneratorService|Date is Mon Dec 12 00:00:00 MSK
1222 -12-18T21:00:00Z
2016-05-25-15:57:16.734 DEBUG|G|rrcsdDocGeneratorService|Local date is 1222-12-18T21:00:00Z

6 days difference!
Why is this happening? Is this a bug or a feature? Can anyone explain?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Kileev, 2016-05-25
@glorfindeil

This is because of the difference between the Julian and Gregorian calendar.
The date API from java.util.* before October 14, 1582 uses the Julian calendar, and after the Gregorian.
The API from java.time.* uses the proleptic Gregorian calendar.
And on the dates indicated, there was just a difference of 8 days between the Julian and the proleptic Gregorian calendar.
https://ru.wikipedia.org/wiki/%D0%9F%D1%80%D0%BE%D...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question