Java Date Time Java Java API
java.time.ZonedDateTime
public ZonedDateTime withHour(int hour)
Returns a copy of this ZonedDateTime 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.zoneddatetime;import java.time.ZonedDateTime;public class WithHourExample { public static void main(String... args) { ZonedDateTime d = ZonedDateTime.now(); System.out.println(d); ZonedDateTime d2 = d.withHour(8); System.out.println(d2); }}
2017-05-01T16:00:11.550-05:00[America/Chicago]2017-05-01T08:00:11.550-05:00[America/Chicago]