How many of the following can fill in the blank so this code compiles and prints 31?
LocalDate xmas = LocalDate.of(2017, 12, 25);
LocalDate blackFriday = LocalDate.of(2017, 11, 24);
long shoppingDaysLeft = ;
System.out.println(shoppingDaysLeft);
I. blackFriday.until(xmas, ChronoUnit.DAYS) II. blackFriday.until(xmas, TemporalUnit.DAYS) III. ChronoUnit.DAYS.between(blackFriday, xmas) IV. TemporalUnit.DAYS.between(blackFriday, xmas)
B.
The TemporalUnit interface does not define a DAYS constant, making II and IV incorrect.
The until()
and between()
methods have the same behavior.
They determine how many units of time are between two dates.
One takes both dates as parameter and the other is an instance method on the date.
Since I and III are equivalent, Option B is the answer.