Close

Java Date Time - OffsetTime.withOffsetSameInstant() Examples

[Last Updated: Nov 8, 2025]

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

21:27:21.163+08:00
17:27:21.163+04:00




See Also