Calculate Difference between 2 LocalDates

suggest change

Use 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 );

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents