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.


withOffsetSameInstant has the following syntax.

public OffsetDateTime withOffsetSameInstant(ZoneOffset offset)


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 l = o.withOffsetSameInstant(ZoneOffset.UTC);

The code above generates the following result.