This method returns a copy of OffsetTime representing the same LocalTime but with offset part adjusted to the provided zone offset.
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