12

I've got two LocalDates:

LocalDate date1;
LocalDate date2;
//...

How to find the number of days between those dates?

user3663882
  • 6,957
  • 10
  • 51
  • 92

2 Answers2

18

LocalDate.until is what you're looking for. (LocalDate implements Temporal, which is what Days accepts, and ChronoUnit is a library of TemporalUnit instances.)

long days = date1.until(date2, ChronoUnit.DAYS);
Jeff Bowman
  • 90,959
  • 16
  • 217
  • 251
9

I would do something like

long daysBetween = DAYS.between(date1, date2);
mattias
  • 2,079
  • 3
  • 20
  • 27