Java SE 8 Programmer II — Question 85

Given the code fragment:
ZonedDateTime depart = ZonedDateTime.of(2015, 1, 15, 1, 0, 0, 0, ZoneID.of("UTC-7"));
ZonedDateTime arrive = ZonedDateTime.of(2015, 1, 15, 9, 0, 0, 0, ZoneID.of("UTC-5")); long hrs = ChronoUnit.HOURS.between(depart, arrive); //line n1
System.out.println("Travel time is" + hrs + "hours");
What is the result?

Answer options

Correct answer: C

Explanation

The correct answer is C because the departure time in UTC-7 and arrival time in UTC-5 results in a total travel time of 8 hours when calculated. Options A and B are incorrect as they do not account for the time zone difference correctly, and option D is wrong because no exception is thrown in this calculation.