~/ learn/ java-from-zero/ cards/ Instant, Duration, Period & ZonedDateTime
1 of 4

Type a Period.between call and read its years

Type a Period.between call and read its years

Answer

Period age = Period.between(birthday, LocalDate.now()); int years = age.getYears();

Period.between takes two LocalDates. The result can be negative if the end is before the start. getYears() reads only the years component, not the total.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/4be45e35-c110-4e2f-9205-5c7609b77ef3/flashcard utf-8 LF