[英]Java: How to get the timestamp of '1000-01-01 00:00:00' in UTC?
I got the timestamp of '1000-01-01 00:00:00' in two different results. 我在两个不同的结果中获得了“ 1000-01-01 00:00:00”的时间戳。 Does anybody know why?
有人知道为什么吗?
TimeZone timeZone = TimeZone.getTimeZone(ZoneOffset.UTC);
GregorianCalendar calendar = new GregorianCalendar(timeZone);
calendar.clear();
calendar.set(1000, 0, 1, 0, 0, 0);
System.out.println(calendar.getTimeInMillis()); // print -30609792000000
System.out.println(ZonedDateTime.of(1000, 1, 1,0, 0, 0, 0, timeZone.toZoneId()).toInstant().toEpochMilli()); // print -30610224000000
GregorianCalendar
despite its name uses the Julian calendar for the time before the Gregorian calendar was introduced from 1582 and onward. GregorianCalendar
尽管使用了公历,但从1582年开始采用公历。 ZonedDateTime
by contrast uses the Proleptic Gregorian calendar , that is, extrapolates the Gregorian calendar into the centuries where it wasn't used at that time. ZonedDateTime
相比之下使用Proleptic公历 ,也就是外推公历进入它并没有在那个时候所使用的世纪。
So you are really using two calendar systems. 因此,您实际上正在使用两个日历系统。 Which explains why you are getting two different results.
这就解释了为什么您得到两个不同的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.