DateTimeFormatter format = DateTimeFormatter.ofPattern("MMM d yyyy hh:mm a");// Leaving from San Francisco on July 20, 2013, at 7:30 p.m.// 出发时间,旧金山(和洛杉矶一个时区?),此时不包含时区信息LocalDateTime leaving = LocalDateTime.of(2013, Month.JULY, 20, 19, 30);ZoneId leavingZone = ZoneId.of("America/Los_Angeles");//包含洛杉矶时区信息的出发时间ZonedDateTime departure = ZonedDateTime.of(leaving, leavingZone);try {String out1 = departure.format(format);System.out.printf("LEAVING: %s (%s)%n", out1, leavingZone);} catch (DateTimeException exc) {System.out.printf("%s can't be formatted!%n", departure);throw exc;}// Flight is 10 hours and 50 minutes, or 650 minutes// 航班历时10小时50分钟,或者换算成650分钟ZoneId arrivingZone = ZoneId.of("Asia/Tokyo");//计算出东京时区降落时的时间ZonedDateTime arrival = departure.withZoneSameInstant(arrivingZone).plusMinutes(650);try {String out2 = arrival.format(format);System.out.printf("ARRIVING: %s (%s)%n", out2, arrivingZone);} catch (DateTimeException exc) {System.out.printf("%s can't be formatted!%n", arrival);throw exc;}if (arrivingZone.getRules().isDaylightSavings(arrival.toInstant()))System.out.printf(" (%s daylight saving time will be in effect.)%n",arrivingZone);elseSystem.out.printf(" (%s standard time will be in effect.)%n",arrivingZone);
