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
您是正确的,
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是正确且聪明的。我只会添加一些想法。时区域跟踪非常新
Transition[Overlap at 1911-03-11T00:00+00:09:21 to Z]
Transition[Gap at 1916-06-14T23:00Z to +01:00]
Transition[Overlap at 1916-10-02T00:00+01:00 to Z]
Transition[Gap at 1917-03-24T23:00Z to +01:00]
Transition[Overlap at 1917-10-08T00:00+01:00 to Z]
Transition[Gap at 1918-03-09T23:00Z to +01:00]
Transition[Overlap at 1918-10-07T00:00+01:00 to Z]
Transition[Gap at 1919-03-01T23:00Z to +01:00]
Transition[Overlap at 1919-10-06T00:00+01:00 to Z]
Transition[Gap at 1920-02-14T23:00Z to +01:00]
Transition[Overlap at 1920-10-24T00:00+01:00 to Z]
Transition[Gap at 1921-03-14T23:00Z to +01:00]
Transition[Overlap at 1921-10-26T00:00+01:00 to Z]
Transition[Gap at 1922-03-25T23:00Z to +01:00]
Transition[Overlap at 1922-10-08T00:00+01:00 to Z]
Transition[Gap at 1923-05-26T23:00Z to +01:00]
Transition[Overlap at 1923-10-07T00:00+01:00 to Z]
Transition[Gap at 1924-03-29T23:00Z to +01:00]
Transition[Overlap at 1924-10-05T00:00+01:00 to Z]
Transition[Gap at 1925-04-04T23:00Z to +01:00]
Transition[Overlap at 1925-10-04T00:00+01:00 to Z]
Transition[Gap at 1926-04-17T23:00Z to +01:00]
Transition[Overlap at 1926-10-03T00:00+01:00 to Z]
Transition[Gap at 1927-04-09T23:00Z to +01:00]
Transition[Overlap at 1927-10-02T00:00+01:00 to Z]
Transition[Gap at 1928-04-14T23:00Z to +01:00]
Transition[Overlap at 1928-10-07T00:00+01:00 to Z]
Transition[Gap at 1929-04-20T23:00Z to +01:00]
Transition[Overlap at 1929-10-06T00:00+01:00 to Z]
Transition[Gap at 1930-04-12T23:00Z to +01:00]
Transition[Overlap at 1930-10-05T00:00+01:00 to Z]
Transition[Gap at 1931-04-18T23:00Z to +01:00]
Transition[Overlap at 1931-10-04T00:00+01:00 to Z]
Transition[Gap at 1932-04-02T23:00Z to +01:00]
Transition[Overlap at 1932-10-02T00:00+01:00 to Z]
Transition[Gap at 1933-03-25T23:00Z to +01:00]
Transition[Overlap at 1933-10-08T00:00+01:00 to Z]
Transition[Gap at 1934-04-07T23:00Z to +01:00]
Transition[Overlap at 1934-10-07T00:00+01:00 to Z]
Transition[Gap at 1935-03-30T23:00Z to +01:00]
Transition[Overlap at 1935-10-06T00:00+01:00 to Z]
Transition[Gap at 1936-04-18T23:00Z to +01:00]
Transition[Overlap at 1936-10-04T00:00+01:00 to Z]
Transition[Gap at 1937-04-03T23:00Z to +01:00]
Transition[Overlap at 1937-10-03T00:00+01:00 to Z]
Transition[Gap at 1938-03-26T23:00Z to +01:00]
Transition[Overlap at 1938-10-02T00:00+01:00 to Z]
Transition[Gap at 1939-04-15T23:00Z to +01:00]
Transition[Overlap at 1939-11-19T00:00+01:00 to Z]
Transition[Gap at 1940-02-25T02:00Z to +01:00]
Transition[Gap at 1940-06-14T23:00+01:00 to +02:00]
Transition[Overlap at 1942-11-02T03:00+02:00 to +01:00]
Transition[Gap at 1943-03-29T02:00+01:00 to +02:00]
Transition[Overlap at 1943-10-04T03:00+02:00 to +01:00]
Transition[Gap at 1944-04-03T02:00+01:00 to +02:00]
Transition[Overlap at 1944-10-08T01:00+02:00 to +01:00]
Transition[Gap at 1945-04-02T02:00+01:00 to +02:00]
Transition[Overlap at 1945-09-16T03:00+02:00 to +01:00]
Transition[Gap at 1976-03-28T01:00+01:00 to +02:00]
Transition[Overlap at 1976-09-26T01:00+02:00 to +01:00]
Transition[Gap at 1977-04-03T02:00+01:00 to +02:00]
Transition[Overlap at 1977-09-25T03:00+02:00 to +01:00]
Transition[Gap at 1978-04-02T02:00+01:00 to +02:00]
Transition[Overlap at 1978-10-01T03:00+02:00 to +01:00]
Transition[Gap at 1979-04-01T02:00+01:00 to +02:00]
Transition[Overlap at 1979-09-30T03:00+02:00 to +01:00]
Transition[Gap at 1980-04-06T02:00+01:00 to +02:00]
Transition[Overlap at 1980-09-28T03:00+02:00 to +01:00]
Transition[Gap at 1981-03-29T02:00+01:00 to +02:00]
Transition[Overlap at 1981-09-27T03:00+02:00 to +01:00]
Transition[Gap at 1982-03-28T02:00+01:00 to +02:00]
Transition[Overlap at 1982-09-26T03:00+02:00 to +01:00]
Transition[Gap at 1983-03-27T02:00+01:00 to +02:00]
Transition[Overlap at 1983-09-25T03:00+02:00 to +01:00]
Transition[Gap at 1984-03-25T02:00+01:00 to +02:00]
Transition[Overlap at 1984-09-30T03:00+02:00 to +01:00]
Transition[Gap at 1985-03-31T02:00+01:00 to +02:00]
Transition[Overlap at 1985-09-29T03:00+02:00 to +01:00]
Transition[Gap at 1986-03-30T02:00+01:00 to +02:00]
Transition[Overlap at 1986-09-28T03:00+02:00 to +01:00]
Transition[Gap at 1987-03-29T02:00+01:00 to +02:00]
Transition[Overlap at 1987-09-27T03:00+02:00 to +01:00]
Transition[Gap at 1988-03-27T02:00+01:00 to +02:00]
Transition[Overlap at 1988-09-25T03:00+02:00 to +01:00]
Transition[Gap at 1989-03-26T02:00+01:00 to +02:00]
Transition[Overlap at 1989-09-24T03:00+02:00 to +01:00]
Transition[Gap at 1990-03-25T02:00+01:00 to +02:00]
Transition[Overlap at 1990-09-30T03:00+02:00 to +01:00]
Transition[Gap at 1991-03-31T02:00+01:00 to +02:00]
Transition[Overlap at 1991-09-29T03:00+02:00 to +01:00]
Transition[Gap at 1992-03-29T02:00+01:00 to +02:00]
Transition[Overlap at 1992-09-27T03:00+02:00 to +01:00]
Transition[Gap at 1993-03-28T02:00+01:00 to +02:00]
Transition[Overlap at 1993-09-26T03:00+02:00 to +01:00]
Transition[Gap at 1994-03-27T02:00+01:00 to +02:00]
Transition[Overlap at 1994-09-25T03:00+02:00 to +01:00]
Transition[Gap at 1995-03-26T02:00+01:00 to +02:00]
Transition[Overlap at 1995-09-24T03:00+02:00 to +01:00]
Transition[Gap at 1996-03-31T02:00+01:00 to +02:00]
Transition[Overlap at 1996-10-27T03:00+02:00 to +01:00]
Transition[Gap at 1997-03-30T02:00+01:00 to +02:00]
Transition[Overlap at 1997-10-26T03:00+02:00 to +01:00]
我们发现巴黎地区在不同时间使用了四个偏移:+00:09:21
+00:00
+01:00
+02:00
OffsetDateTime
最初是因为时区是一项新的发明,只能追溯到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
) // Returns an `OffsetDateTime` object.
.atZoneSameInstant(
ZoneId.of( "Europe/Paris" )
) // Returns a `ZonedDateTime` object.
OffsetDateTime
或ZonedDateTime
通常是不明智的。他们的使用暗示了不可能的精确性和权威性,也可能是不必要的。
定义:
偏移仅是一个小时的时间前/后面的颞子午线。如上所述,在诸如
之类的现代协议中,我们通常使用UTC的子午线,而某些协议则使用巴黎子午线(或其他协议)。和ISO 8601和其他常见协议使用
+
-
时区被称为过去,现在和将来的历史,对特定地区人民所使用的偏移的变化,如其政客所决定。现代区域的命名为
Continent/Region
,
Europe/Paris
,America/Edmonton
等。