Java LocalDateTime Calculate clampDateTimeWithMaxAllowedHour(LocalDateTime dateTime, int maxAllowedHour)

Here you can find the source of clampDateTimeWithMaxAllowedHour(LocalDateTime dateTime, int maxAllowedHour)

Description

Clamp the dateTime so that the latest hour can only be maxAllowedHour.

License

Open Source License

Declaration

public static LocalDateTime clampDateTimeWithMaxAllowedHour(LocalDateTime dateTime, int maxAllowedHour) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.time.LocalDateTime;

public class Main {
    /**/* w  ww  . j  a  va 2s  .  c  om*/
     * Clamp the dateTime so that the latest hour can only be maxAllowedHour.
     */
    public static LocalDateTime clampDateTimeWithMaxAllowedHour(LocalDateTime dateTime, int maxAllowedHour) {
        if (dateTime.getHour() >= maxAllowedHour) {
            return dateTime.withHour(maxAllowedHour).withMinute(0);
        }

        return dateTime;
    }
}

Related

  1. balanceStartAndEndDateTime(LocalDateTime startDateTime, LocalDateTime endDateTime)
  2. before(LocalDateTime time1, LocalDateTime time2)
  3. calcNextDayOfWeekFromLDT(LocalDateTime ldt, DayOfWeek dow)
  4. ceilDate(LocalDateTime dateTime)
  5. checkIfTimeExist(LocalDateTime date)
  6. convertDatabaseDateToUSTime(LocalDateTime databaseDate)
  7. converterZoneDatetimeToLocalDateTime( final String date)
  8. currentTimeMillis(LocalDateTime ldt)
  9. DateTime2LocalDateTime(Date datetime)