nerdexam
Oracle

1Z0-809 · Question #42

Given the code fragment: ZonedDateTime departure = ZonedDateTime.of(2015, 1, 15, 3, 0, 0, 0, ZoneId.of("UTC-5")); ZonedDateTime arrive = ZonedDateTime.of(2015, 1, 15, 9, 0, 0, 0…

The correct answer is B. Travel time is 6 hours. Option B is correct because both departure and arrive are in the same timezone (UTC-5), so ChronoUnit.HOURS.between() simply computes the wall-clock difference: 09:00 minus 03:00 equals exactly 6 hours. No timezone conversion happens because there is no zone change - the JVM…

Question

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

Options

  • ATravel time is 4 hours
  • BTravel time is 6 hours
  • CTravel time is 8 hours
  • DAn exception is thrown at line n1.

How the community answered

(28 responses)
  • A
    4% (1)
  • B
    79% (22)
  • C
    4% (1)
  • D
    14% (4)

Explanation

Option B is correct because both departure and arrive are in the same timezone (UTC-5), so ChronoUnit.HOURS.between() simply computes the wall-clock difference: 09:00 minus 03:00 equals exactly 6 hours. No timezone conversion happens because there is no zone change - the JVM calculates the elapsed time as a straightforward arithmetic difference.

Why the distractors are wrong:

  • A (4 hours) and C (8 hours) are trap answers that suggest some timezone arithmetic is occurring. They would be plausible if the arrival zone were different (e.g., UTC+1 or UTC-8), but since both times share UTC-5, no offset math applies.
  • D (exception at line n1) is tempting because the variable is declared as departure but the code calls it depart - a typo in the question. If taken literally, this would cause a compile-time error (not a runtime exception), but exam questions like this typically treat it as a typo and expect you to reason about the logic, not the typo.

Memory tip: When you see ChronoUnit.HOURS.between() with two ZonedDateTime values, ask yourself one question: are the zones different? If yes, the library normalizes to UTC first. If no (same zone), it's pure subtraction - what you see on the clock is what you get.

Community Discussion

No community discussion yet for this question.

Full 1Z0-809 Practice