LocalDateTime withHour(int hour) example
Description
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 . jav a 2 s . c o m
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.