Close

Java Date Time - OffsetTime.withOffsetSameLocal() 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 withOffsetSameLocal(ZoneOffset offset)

This method returns a copy of OffsetTime representing the same LocalTime but with offset part adjusted to the provided zone offset.



Examples


package com.logicbig.example.offsettime;

import java.time.OffsetTime;
import java.time.ZoneOffset;

public class WithOffsetSameLocalExample {

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

OffsetTime t2 = t.withOffsetSameLocal(ZoneOffset.ofHours(4));
System.out.println(t2);

}
}

Output

16:12:44.694-05:00
16:12:44.694+04:00




See Also