Example usage for java.time ZonedDateTime withZoneSameLocal

List of usage examples for java.time ZonedDateTime withZoneSameLocal

Introduction

In this page you can find the example usage for java.time ZonedDateTime withZoneSameLocal.

Prototype

@Override
public ZonedDateTime withZoneSameLocal(ZoneId zone) 

Source Link

Document

Returns a copy of this date-time with a different time-zone, retaining the local date-time if possible.

Usage

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime dateTime = ZonedDateTime.now();
    ZonedDateTime l = dateTime.withZoneSameLocal(ZoneId.systemDefault());
    System.out.println(l);/* ww w .j  av  a  2  s  .co  m*/
}

From source file:Main.java

public static void main(String[] args) {
    LocalDateTime localDateTime = LocalDateTime.of(1982, Month.APRIL, 17, 14, 11);
    ZonedDateTime jakartaTime = ZonedDateTime.of(localDateTime, ZoneId.of("Asia/Jakarta"));
    System.out.println(jakartaTime); //1982-04-17T14:11+07:00[Asia/Jakarta]

    System.out.println(jakartaTime.withZoneSameInstant(ZoneId.of("America/Los_Angeles"))); //1982-04-16T23:11-08:00[America/Los_Angeles]
    System.out.println(jakartaTime.withZoneSameLocal(ZoneId.of("America/New_York"))); //1982-04-17T14:11-05:00[America/New_York]

}