Java Date Time - OffsetDateTime atZoneSimilarLocal(ZoneId zone) example








OffsetDateTime atZoneSimilarLocal(ZoneId zone) combines this date-time with a time-zone to create a ZonedDateTime trying to keep the same local date and time.

Syntax

atZoneSimilarLocal has the following syntax.

public ZonedDateTime atZoneSimilarLocal(ZoneId zone)

Example

The following example shows how to use atZoneSimilarLocal.

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

The code above generates the following result.