This answer fixes the problem of the .get(ChronoUnits.DAYS) response .get(ChronoUnits.DAYS) returns only a fraction of the days in duration, not the total number of days.
Import and initialization required
import java.time.temporal.ChronoUnit import java.time.{LocalDate, Period}
Please note that the above answer may lead to an incorrect result (total number of days is 117)
scala> Period.between(start, end) res6: java.time.Period = P3M26D scala> Period.between(start, end).get(ChronoUnit.DAYS) res7: Long = 26
Iterate over specific dates between start and end
val start = LocalDate.of(2018, 1, 5) val end = LocalDate.of(2018, 5, 1) // Create List of 'LocalDate' for the period between start and end date val dates: IndexedSeq[LocalDate] = (0L to (end.toEpochDay - start.toEpochDay)) .map(days => start.plusDays(days)) dates.foreach(println)
source share