← Quiz: Date and Time in Java: all 10 questions
Quiz: Date and Time in Java · Question 4 of 10
You need the total number of days from today until an exam. Which is correct?
You need the total number of days from today until an exam. Which is correct?
- A.Period.between(today, exam).getDays()
- B.ChronoUnit.DAYS.between(today, exam)
- C.Duration.between(today, exam).toDays() on two LocalDate values
- D.exam.getDayOfMonth() - today.getDayOfMonth()
Answer & explanation
Correct answer: ChronoUnit.DAYS.between(today, exam)
Period.getDays gives only the days part (ignoring months); ChronoUnit.DAYS.between gives the full count.
Can you get the rest right without peeking?
Take the timed Quiz: Date and Time in Java quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →