简体   繁体   English

Java:如何在UTC中获取时间戳“ 1000-01-01 00:00:00”?

[英]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.

相关问题 如何将 2017-08-01T16:00:00-04:00 转换为 Java 中的时间戳? - How to convert 2017-08-01T16:00:00-04:00 to timestamp in Java? 如何获取此字符串的 08:00 2015-01-01T08:00:00-02:00 - How to get 08:00 of this String 2015-01-01T08:00:00-02:00 如何反序列化日期'2017-01-01T00:00:59.000UTC' - How to deserialize date '2017-01-01T00:00:59.000UTC' 如何在 -01:-05:00 到 -01:05:00 中制作时间格式 - how to make a time format in -01:-05:00 to -01:05:00 java:如何将日期从“ 2014年5月1日星期四00:00:00西部”投射到“ 2014-01-05 00:00:00.0” - java : How can I cast Date from “Thu May 01 00:00:00 WEST 2014 ” to “2014-01-05 00:00:00.0” java.text.ParseException:无法解析的日期:“1901-01-01 00:00:00” - java.text.ParseException: Unparseable date: “1901-01-01 00:00:00” 如何更改 LocalDateTime 的默认纪元 1970-01-01T00:00:00Z - How to change the default epoch of 1970-01-01T00:00:00Z for LocalDateTime 将字符串解析为时间使得01:00:00 - Parsing String to Time makes 01:00:00 Rest API的Java日期,例如:1990年1月1日,星期一,格林尼治标准时间 - Java date for Rest API like this: Mon, 01 Jan 1990 00:00:00 GMT 如何获取Spring Boot API返回MySQL日期值的UTC时间而不是“ 2018-08-01T04:00:00Z”? - How do I get my Spring Boot API to return UTC times for MySQL Date values instead of “2018-08-01T04:00:00Z”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM