Close

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

This method returns a copy of OffsetTime representing the same instance as of this time but adjusted to the provided zone offset.



Examples


package com.logicbig.example.offsettime;

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

public class WithOffsetSameInstantExample {

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

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

Output

16:12:46.762-05:00
01:12:46.762+04:00




See Also