我在两个不同的结果中得到了1000-01-01 00:00:00"的时间戳.有人知道为什么吗?
I got the timestamp of '1000-01-01 00:00:00' in two different results. 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 尽管它的名字使用的是儒略历,但在公历从 1582 年开始引入之前.相比之下,ZonedDateTime 使用 Proleptic 公历a>,也就是说,将公历外推到当时没有使用它的世纪.
GregorianCalendar despite its name uses the Julian calendar for the time before the Gregorian calendar was introduced from 1582 and onward. 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.
所以您实际上是在使用两个日历系统.这就解释了为什么你会得到两个不同的结果.
So you are really using two calendar systems. Which explains why you are getting two different results.
这篇关于Java:如何在 UTC 中获取“1000-01-01 00:00:00"的时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
解析 ISO 8601 字符串本地日期时间,就像在 UTC 中Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期时间,就像在 UTC 中一样)
如何将公历字符串转换为公历?How to convert Gregorian string to Gregorian Calendar?(如何将公历字符串转换为公历?)
Java:GregorianCalendar 的最大值和最小值是什么/在哪Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
1582 年 10 月 15 日之前日期的日历到日期转换.公历Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日历到日期转换
java日历setFirstDayOfWeek不起作用java Calendar setFirstDayOfWeek not working(java日历setFirstDayOfWeek不起作用)
Java:获取当前星期几的值Java: getting current Day of the Week value(Java:获取当前星期几的值)