Java Utililty Methods LocalDate Between

List of utility methods to do LocalDate Between

Description

The list of methods to do LocalDate Between are organized into topic(s).

Method

intdaysBetween(LocalDate date1, LocalDate date2)
days Between
Period period = Period.between(date1, date2);
return period.getDays();
longdaysBetween(LocalDate firstDate, LocalDate secondDate)
Returns the number of days between two dates.
int firstYear = firstDate.getYear();
int secondYear = secondDate.getYear();
if (firstYear == secondYear) {
    return doy(secondDate) - doy(firstDate);
if ((firstYear + 1) == secondYear) {
    return (firstDate.lengthOfYear() - doy(firstDate)) + doy(secondDate);
return secondDate.toEpochDay() - firstDate.toEpochDay();
ListgetLocalDatesBetween(final LocalDate localDate1, final LocalDate localDate2)
get Local Dates Between
if (localDate1 == null || localDate2 == null) {
    return Collections.emptyList();
if (localDate1.equals(localDate2)) {
    return Lists.newArrayList(localDate1);
final int daysBetween = (int) Math.abs(ChronoUnit.DAYS.between(localDate1, localDate2));
final List<LocalDate> localDatesBetween = Lists.newArrayListWithExpectedSize(daysBetween + 1);
...
LocalDategetRandomLocalDateBetween(int startYear, int endYear)
get Random Local Date Between
Random random = new Random();
int min = (int) LocalDate.of(startYear, 1, 1).toEpochDay();
int max = (int) LocalDate.of(endYear, 1, 1).toEpochDay();
long randomDay = min + random.nextInt(max - min);
return LocalDate.ofEpochDay(randomDay);
BooleanisBetween(LocalDate date, LocalDate before, LocalDate after)
is Between
return date.isAfter(before) && date.isBefore(after);
booleanisBetween13And18YearsBetween(LocalDate birthLocalDate, LocalDate now)
is Between And Years Between
int years = Period.between(birthLocalDate, now).getYears();
return years >= 13 && years < 18;
booleanisBetweenDates(LocalDate date, LocalDate start, LocalDate end)
is Between Dates
return date.isAfter(start) && date.isBefore(end);
booleanisBetweenIncl(@Nullable final LocalDate aDate, @Nullable final LocalDate aLowerBound, @Nullable final LocalDate aUpperBound)
is Between Incl
if (aDate == null || aLowerBound == null || aUpperBound == null)
    return false;
return !aLowerBound.isAfter(aDate) && !aDate.isAfter(aUpperBound);