Returns a copy of this OffsetDateTime with the hour-of-day changed with the provided hour.
If the provided 'hour' is not valid, this method will throw java.time.DateTimeException. The valid values are 0 - 23.
package com.logicbig.example.offsetdatetime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
public class WithHourExample {
public static void main(String... args) {
OffsetDateTime d = OffsetDateTime.of(2015, 10, 5, 15,
30, 10, 1000000, ZoneOffset.ofHours(-5));
System.out.println(d);
OffsetDateTime d2 = d.withHour(11);
System.out.println(d2);
}
}
Output
2015-10-05T15:30:10.001-05:00
2015-10-05T11:30:10.001-05:00