1

im trying to understand the concept of UTC and the new TimeApi from Java 8.

Instant from = Instant.from(ZonedDateTime.of(2016, 12, 11, 00, 23, 24, 245, ZoneId.systemDefault()));
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Date date = simpleDateFormat.parse("2016-06-10 21:19:18");

System.out.println("Case1:");
System.out.println(date.toInstant());
System.out.println(ZonedDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()));

System.out.println("Case2:");
System.out.println(from);
System.out.println(ZonedDateTime.ofInstant(from, ZoneId.systemDefault()));

The following output is printed:

Case1:
2016-06-10T19:19:18Z
2016-06-10T21:19:18+02:00[Europe/Berlin]

Case2:
2016-12-10T23:23:24.000000245Z
2016-12-11T00:23:24.000000245+01:00[Europe/Berlin]

Why the Zone Offset in Case1 is +02:00Hours, in Case2 +01:00Hour?

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
Hakan Kiyar
  • 1,199
  • 6
  • 16
  • 26

1 Answers1

3

2016-06-10T19:19:18Z is in June (when Berlin is in Daylight Savings Time: Central European Summer Time).

2016-12-10T23:23:24.000000245Z is in December (when Berlin is not in Daylight Savings Time: Central European Time).

Hence the UTC offsets are different.

Andy Turner
  • 137,514
  • 11
  • 162
  • 243