Skip to content
Sharp

API Evolution · interview question

How would you calculate the number of days between two java.time.LocalDate objects?

Multiple choiceHardchapter-12-curatedpremiumapi-evolutionmodern-date-and-time
Choose one answer
Answer and explanation

Correct answer

A. Use date1.until(date2, ChronoUnit.DAYS)

Why

The method date1.until(date2, ChronoUnit.DAYS) calculates the number of days between two LocalDate instances. It is a direct approach to obtain the difference in a specified unit.

Test yourself on API Evolution

A free test with instant, explained results. No account needed.

Start free test
All API Evolution questions →