我试图从 Java 8 中理解 UTC 和新 TimeApi 的概念。
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()));
打印以下输出:
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]
为什么区域偏移量Case1
是 +02:00
小时,以Case2
+01:00
小时为单位?