Java LocalDate Between getRandomLocalDateBetween(int startYear, int endYear)

Here you can find the source of getRandomLocalDateBetween(int startYear, int endYear)

Description

get Random Local Date Between

License

Open Source License

Declaration

public static LocalDate getRandomLocalDateBetween(int startYear, int endYear) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.time.LocalDate;

import java.util.Random;

public class Main {
    public static LocalDate getRandomLocalDateBetween(int startYear, int endYear) {
        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);
    }/*from  w  ww  . ja va 2s. c  o m*/
}

Related

  1. daysBetween(LocalDate date1, LocalDate date2)
  2. daysBetween(LocalDate firstDate, LocalDate secondDate)
  3. getLocalDatesBetween(final LocalDate localDate1, final LocalDate localDate2)
  4. isBetween(LocalDate date, LocalDate before, LocalDate after)
  5. isBetween13And18YearsBetween(LocalDate birthLocalDate, LocalDate now)
  6. isBetweenDates(LocalDate date, LocalDate start, LocalDate end)
  7. isBetweenIncl(@Nullable final LocalDate aDate, @Nullable final LocalDate aLowerBound, @Nullable final LocalDate aUpperBound)