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