Java Utililty Methods LocalDateTime Calculate

List of utility methods to do LocalDateTime Calculate

Description

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

Method

ZonedDateTimegetZonedDateTime(LocalDateTime dateTime, TimeZone timeZone)
get Zoned Date Time
ZoneId zoneId = timeZone.toZoneId();
return dateTime.atZone(zoneId);
booleanisAfter(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;
booleanisAfterNow(LocalDateTime pValidUntil)
is After Now
if (pValidUntil != null) {
    LocalDateTime now = LocalDateTime.now();
    return pValidUntil.isAfter(now);
return true;
booleanisBefore(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);
booleanisOverdue(LocalDateTime dueTime)
Checks against system time if the provided dueTime is before system time.
return dueTime.isBefore(LocalDateTime.now());
booleanisToday(LocalDateTime dateTime)
Check if datetime is from today
LocalDate today = LocalDate.now();
LocalDate date = dateTime.toLocalDate();
return date.equals(today);
BooleanisTodayOrYesterday(LocalDateTime date)
is Today Or Yesterday
return date.toLocalDate().equals(getDateTime().toLocalDate())
        || date.toLocalDate().equals(getDateTime().toLocalDate().minusDays(1));
PredicateisWithin(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);
LocalDateTimelast(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);
...
LocalDatelocalDateTime2LocalDate(LocalDateTime localDateTime)
local Date Time Local Date
return localDateTime.toLocalDate();