How to find the number of days between the java interface of LocalDate?

I have two LocalDates:

LocalDate date1;
LocalDate date2;
//...

How to find the number of days between these dates?

+4
source share
2 answers

LocalDate.until- this is what you are looking for. (LocalDate implements Temporal, which takes days, and ChronoUnit is a library of TemporalUnit instances.)

long days = date1.until(date2, ChronoUnit.DAYS);
+8
source

I would do something like

long daysBetween = DAYS.between(date1, date2);
+4
source

All Articles