Java Date Time - ZonedDateTime withHour(int hour) example








ZonedDateTime withHour(int hour) returns a copy of this ZonedDateTime with the hour-of-day value altered.

Syntax

withHour has the following syntax.

public ZonedDateTime withHour(int hour)

Example

The following example shows how to use withHour.

import java.time.ZonedDateTime;

public class Main {
  public static void main(String[] args) {
    ZonedDateTime dateTime = ZonedDateTime.now();
    ZonedDateTime n = dateTime.withHour(14);
    System.out.println(n);
  } 
}

The code above generates the following result.