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

LocalDategetDate(Console console, Function validator)
get Date
if (validator == null)
    validator = value -> true;
String dateStr;
LocalDate localDate;
do {
    dateStr = getString(console, value -> datePattern.matcher(value).matches());
    try {
        localDate = LocalDate.parse(dateStr, dateFormatter);
...
DategetDate(final LocalDate localDate)
get Date
Instant instant = localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();
return Date.from(instant);
DategetDate(LocalDate d, String tzId)
get Date
return getDate(d.atStartOfDay(), tzId);
StringgetDateCriteria(LocalDate startDate, LocalDate endDate)
get Date Criteria
return "startDate = " + startDate.format(formatter) + " and endDate = " + endDate.format(formatter);
DategetDateStart(LocalDate localDate)
get Date Start
LocalDateTime localDateTime = localDate.atStartOfDay();
ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.of("Asia/Shanghai"));
return Date.from(zonedDateTime.toInstant());
LocalDategetEndDateOfMonth(LocalDate date)
get End Date Of Month
int[] ends = { 31, 30, 29, 28 };
for (int e : ends) {
    try {
        LocalDate eom = date.withDayOfMonth(e);
        return eom;
    } catch (Exception ex) {
return null;
LocalDategetFirstDayOfTheMonth(final LocalDate date)
Returns a leveled date representing the first day of the month based on a specified date.
return date.with(TemporalAdjusters.firstDayOfMonth());
intgetLastDayInMonth(LocalDate localDate)
get Last Day In Month
LocalDate result = localDate.with(TemporalAdjusters.lastDayOfMonth());
return result.getDayOfMonth();
LocalDategetLastDayOfTheQuarter(final LocalDate date)
Returns a LocalDate date representing the last day of the quarter based on a specified date.
Objects.requireNonNull(date);
LocalDate result;
LocalDate[] bounds = getQuarterBounds(date);
if (date.compareTo(bounds[2]) < 0) {
    result = bounds[1];
} else if (date.compareTo(bounds[4]) < 0) {
    result = bounds[3];
} else if (date.compareTo(bounds[6]) < 0) {
...
LocalDategetLocalDateBydayAndWeek(LocalDate localDate, int weekNumber, int dayNumber)
get Local Date Byday And Week
return localDate.with(TemporalAdjusters.dayOfWeekInMonth(weekNumber, DayOfWeek.of(dayNumber)));