Java Date Time - OffsetTime withOffsetSameInstant( ZoneOffset offset) example








OffsetTime withOffsetSameInstant(ZoneOffset offset) returns a copy of this OffsetTime with the specified offset ensuring that the result is at the same instant on an implied day.

Syntax

withOffsetSameInstant has the following syntax.

public OffsetTime withOffsetSameInstant(ZoneOffset offset)

Example

The following example shows how to use withOffsetSameInstant.

import java.time.OffsetTime;
import java.time.ZoneOffset;
//w  w w. j  a va  2  s. c  o m
public class Main {
  public static void main(String[] args) {
    OffsetTime m = OffsetTime.now();
    OffsetTime l = m.withOffsetSameInstant(ZoneOffset.UTC);
    System.out.println(l);

  }
}

The code above generates the following result.