Java: How to get the timestamp of #39;1000-01-01 00:00:00#39; in UTC?(Java:如何在 UTC 中获取“1000-01-01 00:00:00的时间戳?)
问题描述
我在两个不同的结果中得到了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"的时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java:如何在 UTC 中获取“1000-01-01 00:00:00"的时间
基础教程推荐
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 在螺旋中写一个字符串 2022-01-01