It seems like DateTime
does not initialize itself with correct date when we construct it from a java.util.Date
with year 0001
.
import java.time.LocalDateTime;
import java.util.TimeZone;
public class TestMain {
public static void main(String[] args) {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
java.util.Date d = new java.util.Date(-62135640000000L);
java.time.Instant i = java.time.Instant.ofEpochMilli(-62135640000000L);
System.out.println("d = new java.util.Date(-62135640000000L) : " + new java.util.Date(-62135640000000L));
System.out.println("new org.joda.time.DateTime(d) : " + new org.joda.time.DateTime(d));
System.out.println("new org.joda.time.DateTime(-62135640000000L) : " + new org.joda.time.DateTime(-62135640000000L));
System.out.println("java.time.LocalDateTime.ofInstant(i, java.time.ZoneOffset.UTC): " + LocalDateTime.ofInstant(i, java.time.ZoneOffset.UTC));
}
}
output:
d = new java.util.Date(-62135640000000L) : Sun Jan 02 12:00:00 UTC 1
new org.joda.time.DateTime(d) : 0000-12-31T12:00:00.000Z
new org.joda.time.DateTime(-62135640000000L) : 0000-12-31T12:00:00.000Z
java.time.LocalDateTime.ofInstant(i, java.time.ZoneOffset.UTC): 0000-12-31T12:00
Apart from the timezone related differences, if you note:
- the date is
02
inDate
object and31
inDateTime
(or00
if you change toUTC
) - the year is
0001
inDate
object and0000
inDateTime
Am I doing something wrong, or is this a bug?
Did some more calculation
62135640000000 / 1000 / 3600 / 24 / 365.25 = 1968.9596167008898015058179329227
0.9596167008898015058179329227 * 365.25 = 350.5
365.25 - 350.5 = 14.75
So -62135640000000
= negative 1969 years and 350.5 days. Or about 14.75 days after start of year 0000.