Here you can find the source of clampDateTimeWithMaxAllowedHour(LocalDateTime dateTime, int maxAllowedHour)
public static LocalDateTime clampDateTimeWithMaxAllowedHour(LocalDateTime dateTime, int maxAllowedHour)
//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; } }