OffsetDateTime atZoneSimilarLocal(ZoneId zone) example

Description

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;
/*  w  w w .j  a  va  2 s.  c o  m*/
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.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset