Example usage for java.time LocalTime withHour

List of usage examples for java.time LocalTime withHour

Introduction

In this page you can find the example usage for java.time LocalTime withHour.

Prototype

public LocalTime withHour(int hour) 

Source Link

Document

Returns a copy of this LocalTime with the hour-of-day altered.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalTime l = LocalTime.now();
    LocalTime s = l.withHour(4);
    System.out.println(s);//from ww w  . ja  v a2  s  .  c o m
}

From source file:com.haulmont.cuba.web.widgets.CubaTimeField.java

protected LocalTime applyResolutionToValue(LocalTime value) {
    if (value == null) {
        return null;
    }//from w w w.  jav a  2  s  .c  om

    LocalTime result = LocalTime.MIDNIGHT;
    List<TimeResolution> resolutions = getResolutionsHigherOrEqualTo(getResolution())
            .collect(Collectors.toList());

    for (TimeResolution resolution : resolutions) {
        switch (resolution) {
        case HOUR:
            result = result.withHour(value.getHour());
            break;
        case MINUTE:
            result = result.withMinute(value.getMinute());
            break;
        case SECOND:
            result = result.withSecond(value.getSecond());
            break;
        default:
            throw new IllegalArgumentException("Cannot detect resolution type");
        }
    }

    return result;
}