OCP Question 36, Explanation

Given the code fragment:

ZonedDateTime departed = ZonedDateTime.of(1991, 4, 1, 19, 0, 0, 0, ZoneId.of("UTC+3"));
ZonedDateTime arrived = ZonedDateTime.of(1991, 4, 2, 9, 0, 0, 0, ZoneId.of("UTC+9"));
long hrs = ChronoUnit.HOURS.between(departed, arrived);     //line n1
System.out.println("Flight time was " + hrs + " hours");

What is the result?

A. Flight time was 8 hours
B. Flight time was 9 hours
C. Flight time was 10 hours
D. An exception is thrown at line n1


The correct answer is A.


The above code tells of my travel from Moscow to Tokyo on that April Fools’ Day back in 1991 when I left my homeland to explore the world. This is also the only question that concerns time zones on our exam. Although it features many interesting aspects related to LDT classes in Java 8, all you have to know for 1Z0-809 is the abbreviation LTMTZU, which can be easily memorized thanks to the mnemonic formula “let me teaze you”. It stands for

LT – TZ = U         (Local Time Minus Time Zone equals UTC)

We’ll also need to account for the fact that the arrival took place on the next calendar day (by adding 24 hrs). Alright, let’s calculate:

UTC for departure = 19 – (+3) = 16 (where 19 is local time and +3 is time zone offset for Moscow)
UTC for arrival = 24 + 9 – (+9) = 24 (where 9 is local time and +9 is time zone offset for Tokyo).
Time difference = 24 – 16 = 8

The question on the real exam was even easier as everything happened on the same day.

Leave Comment

Your email address will not be published. Required fields are marked *