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

LocalDateTimeadd(final LocalDateTime original, final int years, final int months, final int days, final int hours, final int minutes)
add
return original.plusYears(years).plusMonths(months).plusDays(days).plusHours(hours).plusMinutes(minutes);
LocalDateTimeaddHeureMinute(final LocalDateTime time, final int heures, final int minutes)
add Heure Minute
return time.plus(heures * 60 + minutes, ChronoUnit.MINUTES);
booleanareDatesOneMonthApart(LocalDateTime start, LocalDateTime end)
are Dates One Month Apart
final int startDay = start.getDayOfMonth();
final int endDay = end.getDayOfMonth();
if (startDay == endDay && (start.getMonth() != start.getMonth())) {
    return true;
} else {
    final boolean startAtMonthEnd = (startDay == start.getMonth().length(start.toLocalDate().isLeapYear()));
    final boolean endAtMonthEnd = (endDay == end.getMonth().length(end.toLocalDate().isLeapYear()));
    if (startAtMonthEnd) {
...
LocalDateTimeatMidnight(LocalDateTime value)
at Midnight
return value != null ? value.truncatedTo(ChronoUnit.DAYS) : null;
LocalDateTimebalanceStartAndEndDateTime(LocalDateTime startDateTime, LocalDateTime endDateTime)
Takes two LocalDateTime and balances by ensuring that the latter DateTime is gaurenteed to be later than the former DateTime
LocalDateTime newEndDateTime = endDateTime;
while (startDateTime.compareTo(newEndDateTime) >= 1) {
    newEndDateTime = newEndDateTime.plusDays(1);
return newEndDateTime;
booleanbefore(LocalDateTime time1, LocalDateTime time2)
before
return time1.isBefore(time2);
LocalDatecalcNextDayOfWeekFromLDT(LocalDateTime ldt, DayOfWeek dow)
Like it says
LocalDate d = ldt.toLocalDate();
return calcNextDayOfWeek(d, dow);
LocalDateTimeceilDate(LocalDateTime dateTime)
Performs a "ceiling" operation on a LocalDateTime, and returns a new LocalDateTime with time set to 23:59.
if (dateTime == null) {
    return null;
return dateTime.toLocalDate().atTime(23, 59);
booleancheckIfTimeExist(LocalDateTime date)
check If Time Exist
LocalDateTime currentTime = LocalDateTime.now();
return currentTime.getHour() != date.getHour() || currentTime.getMinute() != date.getMinute();
LocalDateTimeclampDateTimeWithMaxAllowedHour(LocalDateTime dateTime, int maxAllowedHour)
Clamp the dateTime so that the latest hour can only be maxAllowedHour.
if (dateTime.getHour() >= maxAllowedHour) {
    return dateTime.withHour(maxAllowedHour).withMinute(0);
return dateTime;