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

LocalDateconverterToLocalDate(final String date)
converter To Local Date
return LocalDate.parse(date);
StringconvertLocalDateToDatabaseDateString(LocalDate localDate)
convert Local Date To Database Date String
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
return localDate.format(formatter);
LocalDatedateToSystemLocalDate(Date d)
Takes a java.util.Date and turns it into a LocalDate based on the systems default timezone.
return d.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
intdaysAgo(LocalDate pastDate)
days Ago
return 0;
intdoy(LocalDate date)
Finds the day-of-year of the date.
int[] lookup = (date.isLeapYear() ? LEAP : STANDARD);
return lookup[date.getMonthValue()] + date.getDayOfMonth();
char[]fastDateWrite(LocalDate localDate)
fast Date Write
char[] c = new char[10];
int y = localDate.getYear();
c[0] = (char) ('0' + y / 1000);
c[1] = (char) ('0' + ((y % 1000) / 100));
c[2] = (char) ('0' + ((y % 100) / 10));
c[3] = (char) ('0' + (y % 10));
c[4] = (char) ('-');
int m = localDate.getMonthValue();
...
char[]fastDateWriteWeeks(LocalDate localDate)
fast Date Write Weeks
char[] c = new char[7];
int y = localDate.get(yearOfWeek);
c[0] = (char) ('0' + y / 1000);
c[1] = (char) ('0' + ((y % 1000) / 100));
c[2] = (char) ('0' + ((y % 100) / 10));
c[3] = (char) ('0' + (y % 10));
c[4] = (char) ('W');
int w = localDate.get(weekOfYear);
...
intgetAge(LocalDate birthday)
get Age
LocalDate now = LocalDate.now();
int age = now.getYear() - birthday.getYear();
if (age <= 0) {
    return 0;
int currentMonth = now.getMonthValue();
int currentDay = now.getDayOfMonth();
int bornMonth = birthday.getMonthValue();
...
intgetAge(LocalDate birthDay)
get Age
return LocalDate.now().getYear() - birthDay.getYear();
DategetDate(ChronoLocalDate date)
get Date
LocalDate localDate = LocalDate.from(date);
ZoneId zone = ZoneId.systemDefault();
Instant instant = localDate.atStartOfDay().atZone(zone).toInstant();
return Date.from(instant);