Java Date Time Java Java API
java.time.OffsetTime
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.
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); }}
21:27:21.163+08:0017:27:21.163+04:00