IAM in +07:00TimeZone.
为此:
ZonedDateTime.of( LocalDateTime.of( 1899, 12, 31, 23, 9, 20, 0 ), ZoneOffset.UTC )
.withZoneSameInstant( ZoneId.of( "Europe/Paris" ) )
将产生:
1899-12-31T23:18:41+00:09:21[Europe/Paris]
另一方面:
ZonedDateTime.of( LocalDateTime.of( 1899, 12, 31, 23, 9, 20, 0 ), ZoneOffset.UTC )
.withZoneSameInstant( ZoneId.of( "GMT+1" ) )
将产生:1900-01-01T00:09:20+01:00[GMT+01:00]
ZoneId.of( "Europe/Paris" ).getRules().getOffset( LocalDateTime.now() )
和
ZoneId.of( "GMT+1" ).getRules().getOffset( LocalDateTime.now() )
产生
+01:00
?我预计拳头的尝试应该给予
1900-01-01T00:09:20+01:00[Europe/Paris]
。顺便说一句,第一次尝试时
+00:09:21
Europe/Paris
GMT+1
您是正确的,
Instant
和var zdt = ZonedDateTime.of( LocalDateTime.of(1899, 12, 31, 23, 9, 20, 0), ZoneOffset.UTC);
System.out.println(ZoneId.of("Europe/Paris").getRules().getOffset(zdt.toInstant()));
System.out.println(ZoneId.of("GMT+1").getRules().getOffset(zdt.toInstant()));
具有相同的偏移now(2025-02-09),但它们在1899年没有相同的偏移量。
LLET在您实际感兴趣的+00:09:21
+01:00
中打印出他们的偏移量,
Europe/Paris
this thisPrints
System.out.println(ZoneId.of("Europe/Paris").getRules().getTransitions());
+00:09:21来自其中。巴黎直到1911年才标准化时区。它比GMT领先9分钟21秒,因为巴黎就在格林威治的东部。这与巴黎的local的平均时间的GMT相抵消。
时区抵消了整个历史上发生了很大的变化。有关更多详细信息,请参见wikipedia。或者,您可以打印
ZoneId
.of ( "Europe/Paris" )
.getRules ( )
.getTransitions ( )
.forEach (
( ZoneOffsetTransition rule ) -> System.out.println ( rule.toString ( ) )
);
扫描仪aanswer是正确且聪明的。我只会添加一些想法。
时区域跟踪非常新正如在其他答案中建议的那样,让我们看一下其政治家决定的巴黎地区人民使用的偏移的变化历史。
Europe/Paris
我们可以看到,该地区的时区跟踪只能追溯到1911年。在铁路时代之前,几乎不需要设计时间区域。唯一重要的时间是显而易见的自然时间:中午是当太阳直接站在头顶的时候,无论您碰巧站在哪里。中午在西方之前在东方到达。
OffsetDateTime
+比UTC子午线之前+09:21。这解释了您的结果中看到的偏移。 所有这些都是一种漫长的方式,即试图在当代时代以外的时区使用时区几乎没有任何意义。首先,因为时区是一项新发明,只能追溯到1800年代后期。其次,因为从来没有追踪过时区!令人震惊的是,尽管我们有许多大学和政府机构,但没有人烦恼确定时区,并跟踪其偏移的变化。只有在我们一生中,亚瑟·戴维·奥尔森(Arthur David Olson)才进行了一个正式的时区数据库,责任于2005年传给保罗·埃格特我们现在致电
tzdata
.。
因此,您在1899年准确地代表一刻的尝试是不明智的。
ZonedDateTime
.of(
LocalDateTime.of( 1899, 12, 31, 23, 9, 20, 0 ),
ZoneOffset.UTC
)
.withZoneSameInstant(
ZoneId.of( "Europe/Paris" )
)
LLET的分解您的代码。
ZonedDateTime
尽管并不关键,但您对第一部分的使用是误导性的。您正在分配仅偏移而不是时区。所以你应该使用OffsetDateTime
。
OffsetDateTime
.of(
LocalDateTime.of( 1899, 12, 31, 23, 9, 20, 0 ),
ZoneOffset.UTC
)
但是,如上所述,在历史时刻使用OffsetDateTime
或ZonedDateTime
通常是不明智的。他们的使用暗示了不可能的精确性和权威性,也可能是不必要的。
定义:
偏移仅是一个小时的时间前/后面的颞子午线。如上所述,在诸如
之类的现代协议中,我们通常使用UTC的子午线,而某些协议则使用巴黎子午线(或其他协议)。和ISO 8601和其他常见协议使用
+
-
时区被称为过去,现在和将来的历史,对特定地区人民所使用的偏移的变化,如其政客所决定。现代区域的命名为
Continent/Region
,
Europe/London
,Europe/Paris
,America/Edmonton
等。