Java Date Time - OffsetDateTime withHour(int hour) example








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

Syntax

withHour has the following syntax.

public OffsetDateTime withHour(int hour)

Example

The following example shows how to use withHour.

import java.time.OffsetDateTime;

public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.now();
    OffsetDateTime d =  o.withHour(4);
    System.out.println(d);
  }
}

The code above generates the following result.