Calculate Difference between 2 LocalDates
suggest changeUse LocalDate and ChronoUnit:
LocalDate d1 = LocalDate.of(2017, 5, 1);
LocalDate d2 = LocalDate.of(2017, 5, 18);
ChronoUnit is an enum. between takes two Temporal arguments, so the LocalDate values can be passed directly. The result below is 17.
long days = ChronoUnit.DAYS.between(d1, d2);
System.out.println( days );
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents