Java Date Time - OffsetDateTime atZoneSameInstant(ZoneId zone) example








OffsetDateTime atZoneSameInstant(ZoneId zone) combines this date-time with a time-zone to create a ZonedDateTime ensuring that the result has the same instant.

Syntax

atZoneSameInstant has the following syntax.

public ZonedDateTime atZoneSameInstant(ZoneId zone)

Example

The following example shows how to use atZoneSameInstant.

import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
/*from w w w .  j  a  v  a  2s  . co m*/
public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.now();
    ZonedDateTime d =  o.atZoneSameInstant(ZoneId.systemDefault());
    System.out.println(d);
  }
}

The code above generates the following result.