Код: Выделить всё
ZoneId paris = ZoneId.of( "Europe/Paris" );
OffsetDateTime offsetDateTime = OffsetDateTime.of( 2018, 10, 28, 2, 0, 0, 0, ZoneOffset.of( "+01:00" ) );
ZonedDateTime zonedDateTime = offsetDateTime.toZonedDateTime();
System.out.println("ZonedDateTime: " + zonedDateTime);
zonedDateTime = zonedDateTime.withZoneSameInstant( paris );
System.out.println("zonedDateTime.withZoneSameInstant( ZoneId.of( \"Europe/Paris\" ) ): " + zonedDateTime);
System.out.println("zonedDateTime.toOffsetDateTime(): " + zonedDateTime.toOffsetDateTime());
System.out.println("================================================================================================");
LocalDateTime localDateTime2 = LocalDateTime.of( 2018, 10, 28, 2, 0, 0, 0 );
System.out.println("localDateTime2: " + localDateTime2);
ZonedDateTime zonedDateTime2 = ZonedDateTime.of( localDateTime2, paris );
System.out.println("ZonedDateTime.of( localDateTime2, ZoneId.of( \"Europe/Paris\" ) ): " + zonedDateTime2);
localDateTime2 = zonedDateTime2.toLocalDateTime();
System.out.println("zonedDateTime2.toLocalDateTime(): " + localDateTime2);
System.out.println("localDateTime2.atZone( paris ).toOffsetDateTime(): " + localDateTime2.atZone( paris ).toOffsetDateTime());
< /code>
запустить это, получит: < /p>
ZonedDateTime: 2018-10-28T02:00+01:00
zonedDateTime.withZoneSameInstant( ZoneId.of( "Europe/Paris" ) ): 2018-10-28T02:00+01:00[Europe/Paris]
zonedDateTime.toOffsetDateTime(): 2018-10-28T02:00+01:00
================================================================================================
localDateTime2: 2018-10-28T02:00
ZonedDateTime.of( localDateTime2, ZoneId.of( "Europe/Paris" ) ): 2018-10-28T02:00+02:00[Europe/Paris]
zonedDateTime2.toLocalDateTime(): 2018-10-28T02:00
localDateTime2.atZone( paris ).toOffsetDateTime(): 2018-10-28T02:00+02:00
Мой вопрос: почему второй случай имеет смещение +02: 00 ? , Париж имеет сложный исторический часовой пояс, но он/был стабилен в 2018 году, поэтому смещение в то время должно быть +01: 00 . < / P > < b r / > < p r e c l a s s = " l a n g - j a v a P r e t t y P r i n t - O v e r r i d e " > < c o d e > p a r i s . g e t R u l e s ( ) . g e t T r a n s i t i o n s ( ) . f o r E a c h ( S y s t e m . o u t : : p r i n t l n ) ; < b r / > / * R E S U L T < b r / > T r a n s i t i o n [ O v e r l a p a t 1 9 1 1 - 0 3 - 1 1 T 0 0 : 0 0 + 0 0 : 0 9 : 2 1 t o Z ] < b r / > T r a n s i t i o n [ G a p a t 1 9 1 6 - 0 6 - 1 4 T 2 3 : 0 0 Z t o + 0 1 : 0 0 ] < b r / > T r a n s i t i o n [ O v e r l a p a t 1 9 1 6 - 1 0 - 0 2 T 0 0 : 0 0 + 0 1 : 0 0 t o Z ] < b r / > T r a n s i t i o n [ G a p a t 1 9 1 7 - 0 3 - 2 4 T 2 3 : 0 0 Z t o + 0 1 : 0 0 ] < b r / > T r a n s i t i o n [ O v e r l a p a t 1 9 1 7 - 1 0 - 0 8 T 0 0 : 0 0 + 0 1 : 0 0 t o Z ] < b r / > T r a n s i t i o n [ G a p a t 1 9 1 8 - 0 3 - 0 9 T 2 3 : 0 0 Z t o + 0 1 : 0 0 ] < b r / > T r a n s i t i o n [ O v e r l a p a t 1 9 1 8 - 1 0 - 0 7 T 0 0 : 0 0 + 0 1 : 0 0 t o Z ] < b r / > T r a n s i t i o n [ G a p a t 1 9 1 9 - 0 3 - 0 1 T 2 3 : 0 0 Z t o + 0 1 : 0 0 ] < b r / > T r a n s i t i o n [ O v e r l a p a t 1 9 1 9 - 1 0 - 0 6 T 0 0 : 0 0 + 0 1 : 0 0 t o Z ] < b r / > T r a n s i t i o n [ G a p a t 1 9 2 0 - 0 2 - 1 4 T 2 3 : 0 0 Z t o + 0 1 : 0 0 ] < b r / > T r a n s i t i o n [ O v e r l a p a t 1 9 2 0 - 1 0 - 2 4 T 0 0 : 0 0 + 0 1 : 0 0 t o Z ] < b r / > T r a n s i t i o n [ G a p a t 1 9 2 1 - 0 3 - 1 4 T 2 3 : 0 0 Z t o + 0 1 : 0 0 ] < b r / > T r a n s i t i o n [ O v e r l a p a t 1 9 2 1 - 1 0 - 2 6 T 0 0 : 0 0 + 0 1 : 0 0 t o Z ] < b r / > T r a n s i t i o n [ G a p a t 1 9 2 2 - 0 3 - 2 5 T 2 3 : 0 0 Z t o + 0 1 : 0 0 ] < b r / > T r a n s i t i o n [ O v e r l a p a t 1 9 2 2 - 1 0 - 0 8 T 0 0 : 0 0 + 0 1 :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]*/
откуда +02: 00 из?
Подробнее здесь: https://stackoverflow.com/questions/794 ... aldatetime