Java Date Time - LocalDateTime withHour(int hour) example








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

Syntax

withHour has the following syntax.

public LocalDateTime withHour(int hour)

Example

The following example shows how to use withHour.

import java.time.LocalDateTime;
/*from   w ww .  j a  v a2s .  com*/
public class Main {
  public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 01);
    
    LocalDateTime t = a.withHour(12);
    
    System.out.println(t);
  }
}

The code above generates the following result.