Java Date Time Java Java API
java.time.OffsetDateTime
public OffsetDateTime withHour(int hour)
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); }}
2015-10-05T15:30:10.001-05:002015-10-05T11:30:10.001-05:00