OCP Question 27, Explanation

Which statement is true about java.time.Duration?

A. It tracks time zones.
B. It preserves daylight saving time.
C. It defines time-based values.
D. It defines date-based values.


The correct answer is C.


There are two LDT classes on the exam that can be easily confused because their names sort of describe similar concepts: Period and Duration. None of them track time zones or daylight saving rules; this job is for the ZonedDateTime class, so options A and B are out.

Period models amount of time in terms of years, months and days. Unlike Duration, which is always 24hrs long, Period maintains a conceptual day, thus adding a single-day Period at 18:00 results in the next day again at 18:00 even if there was a daylight savings shift.

Duration models amount of time in terms of seconds and nanoseconds. Can be accessed using minutes and hours. In addition, the DAYS unit can be used and is treated as exactly equal to 24 hours, thus ignoring daylight savings effects.

In any event, date-based values are for the LocalDate, LocalDateTime and ZonedDateTime classes, which eliminates option D.

Leave Comment

Your email address will not be published.