Close

Java Date Time - OffsetTime.withHour() Examples

Java Date Time Java Java API 


Class:

java.time.OffsetTime

java.lang.Objectjava.lang.Objectjava.time.OffsetTimejava.time.OffsetTimejava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Method:

public OffsetTime withHour(int hour)

Returns a copy of this OffsetTime 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.offsettime;

import java.time.OffsetTime;

public class WithHourExample {

public static void main(String... args) {
OffsetTime t = OffsetTime.now();
System.out.println(t);

OffsetTime t2 = t.withHour(22);
System.out.println(t2);
}
}

Output

16:12:53.054-05:00
22:12:53.054-05:00




See Also