Java Date Time - OffsetDateTime withOffsetSameInstant( ZoneOffset offset) example








OffsetDateTime withOffsetSameInstant(ZoneOffset offset) returns a copy of this OffsetDateTime with the specified offset ensuring that the result is at the same instant.

Syntax

withOffsetSameInstant has the following syntax.

public OffsetDateTime withOffsetSameInstant(ZoneOffset offset)

Example

The following example shows how to use withOffsetSameInstant.

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

The code above generates the following result.