Close

Java Date Time - ZonedDateTime.withHour() Examples

Java Date Time Java Java API 


Class:

java.time.ZonedDateTime

java.lang.Objectjava.lang.Objectjava.time.ZonedDateTimejava.time.ZonedDateTimejava.time.temporal.TemporalTemporaljava.time.chrono.ChronoZonedDateTimeChronoZonedDateTimejava.io.SerializableSerializableLogicBig

Method:

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.

Examples


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);
}
}

Output

2017-05-01T16:00:11.550-05:00[America/Chicago]
2017-05-01T08:00:11.550-05:00[America/Chicago]




See Also