Java Utililty Methods LocalDate Calculate

List of utility methods to do LocalDate Calculate

Description

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

Method

LocalDatestringDateToLocalDate(String day, String month, String year)
string Date To Local Date
final StringBuilder sb = new StringBuilder().append(month).append("-").append(day).append("-").append(year);
return LocalDate.parse(sb.toString(), simpleDateFormatter);
LocalDatestringToLocalDate(String birthDate)
string To Local Date
if (birthDate.length() != 8) {
    throw new IllegalArgumentException("Birth date must be of form yyyyMMdd, i.e. eight characters long.");
return LocalDate.of(Integer.parseInt(birthDate.substring(0, 4)),
        Integer.parseInt(birthDate.substring(4, 6)), Integer.parseInt(birthDate.substring(6, 8)));
booleansubscriptionDeletionRequired(LocalDate vehicleMotExpiryDate, LocalDate requestDate)
subscription Deletion Required
LocalDate deletionDate = vehicleMotExpiryDate.plusMonths(MONTHS_BEFORE_DELETION);
return (requestDate.isAfter(deletionDate) || requestDate.isEqual(deletionDate));
longtoMilliseconds(LocalDate localDate)
Converts local date time to epoh milliseconds assuming start of the day as time point.
return toMilliseconds(localDate.atStartOfDay());
inttoPgDays(LocalDate date)
to Pg Days
LocalDateTime dateTime = date.atStartOfDay();
long secs = toPgSecs(getSecondsSinceJavaEpoch(dateTime));
return (int) TimeUnit.SECONDS.toDays(secs);
booleanwithinAYearFromNow(LocalDate date)
within A Year From Now
LocalDate withinAYear = LocalDate.of(LocalDate.now().getYear() + 1, LocalDate.now().getMonth(),
        LocalDate.now().getDayOfMonth());
return (date.isBefore(withinAYear) && date.isAfter(LocalDate.now())) || date.isEqual(LocalDate.now());
InstantwithTime(LocalDate day, int hours, int minutes)
with Time
if (day == null) {
    day = LocalDate.now();
LocalDateTime dateTime = LocalDateTime.of(day, LocalTime.of(hours, minutes));
return toInstant(dateTime);
LocalDateyyyyMMddToLocalDate(String dateStr)
yyyy M Mdd To Local Date
if (dateStr == null) {
    return null;
return LocalDate.parse(dateStr, DateTimeFormatter.ofPattern(YYYYMMDD));