Java Date Time - OffsetDateTime withOffsetSameLocal (ZoneOffset offset)








OffsetDateTime withOffsetSameLocal(ZoneOffset offset) returns a copy of this OffsetDateTime with the specified offset ensuring that the result has the same local date-time.

Syntax

withOffsetSameLocal has the following syntax.

public OffsetDateTime withOffsetSameLocal(ZoneOffset offset)

Example

The following example shows how to use withOffsetSameLocal.

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

The code above generates the following result.