Java: 如何获取'1000-01-01 00:00:00'的UTC时间戳?
Java: How to get the timestamp of '1000-01-01 00:00:00' in UTC?
我在两个不同的结果中得到了“1000-01-01 00:00:00”的时间戳。有人知道为什么吗?
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
尽管它的名字在 1582 年及以后引入公历之前使用儒略历。 ZonedDateTime
相比之下使用 Proleptic Gregorian calendar,即将公历外推到当时未使用的世纪。
所以你真的在使用两个日历系统。这就解释了为什么您会得到两个不同的结果。
我在两个不同的结果中得到了“1000-01-01 00:00:00”的时间戳。有人知道为什么吗?
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
尽管它的名字在 1582 年及以后引入公历之前使用儒略历。 ZonedDateTime
相比之下使用 Proleptic Gregorian calendar,即将公历外推到当时未使用的世纪。
所以你真的在使用两个日历系统。这就解释了为什么您会得到两个不同的结果。