2016-06-10 7 views
0

im das Konzept der UTC und die neue TimeApi von Java 8.Verwirrt über Instant ZonedDateTime und UTC

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())); 

Die folgende Ausgabe gedruckt wird, versuchen zu verstehen,:

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] 

Warum die Zone Offset in Case1 ist +02:00 Stunden, in Case2+01:00 Stunde?

Antwort

2

2016-06-10T19:19:18Z ist im Juni (wenn Berlin in Sommerzeit ist: Central European Summer Time).

2016-12-10T23:23:24.000000245Z ist im Dezember (wenn Berlin nicht in der Sommerzeit ist: Central European Time).

Daher sind die UTC-Offsets unterschiedlich.

+0

Natürlich! Mein Fehler! :-)))))) –