List of utility methods to do LocalDateTime Calculate
ZonedDateTime | getZonedDateTime(LocalDateTime dateTime, TimeZone timeZone) get Zoned Date Time ZoneId zoneId = timeZone.toZoneId();
return dateTime.atZone(zoneId);
|
boolean | isAfter(LocalDateTime endDateTime, LocalDateTime startDateTime) Checks id the end date time is after start date time if (isNotNull(endDateTime) && isNotNull(startDateTime)) { return endDateTime.isAfter(startDateTime); return false; |
boolean | isAfterNow(LocalDateTime pValidUntil) is After Now if (pValidUntil != null) { LocalDateTime now = LocalDateTime.now(); return pValidUntil.isAfter(now); return true; |
boolean | isBefore(LocalDateTime dateTime1, LocalDateTime dateTime2) Check if a dateTime is before another datetime null dateTime is considered to be after if (dateTime2 == null) { return true; if (dateTime1 == null) { return false; return dateTime1.isBefore(dateTime2); |
boolean | isOverdue(LocalDateTime dueTime) Checks against system time if the provided dueTime is before system time. return dueTime.isBefore(LocalDateTime.now());
|
boolean | isToday(LocalDateTime dateTime) Check if datetime is from today LocalDate today = LocalDate.now();
LocalDate date = dateTime.toLocalDate();
return date.equals(today);
|
Boolean | isTodayOrYesterday(LocalDateTime date) is Today Or Yesterday return date.toLocalDate().equals(getDateTime().toLocalDate())
|| date.toLocalDate().equals(getDateTime().toLocalDate().minusDays(1));
|
Predicate | isWithin(LocalDateTime start, LocalDateTime end) Returns a Predicate that returns true if a LocalDateTime is between two others. if (!start.isBefore(end)) { throw new IllegalArgumentException("Start " + start + " must be before end " + end); return dt -> !dt.isBefore(start) && dt.isBefore(end); |
LocalDateTime | last(LocalDateTime from, int dayOfWeek) last int start = from.getDayOfWeek().getValue(); if (start == 0) { start = 7; if (dayOfWeek == 0) { dayOfWeek = 7; return from.plusDays(dayOfWeek - start - 7); ... |
LocalDate | localDateTime2LocalDate(LocalDateTime localDateTime) local Date Time Local Date return localDateTime.toLocalDate();
|