This method returns a copy of OffsetTime representing the same instance as of this time but adjusted to the provided zone offset.
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