Java Date Time - ZonedDateTime withZoneSameLocal(ZoneId zone) example








ZonedDateTime withZoneSameLocal(ZoneId zone) returns a copy of this date-time with a different time-zone, retaining the local date-time if possible.

Syntax

withZoneSameLocal has the following syntax.

public ZonedDateTime withZoneSameLocal(ZoneId zone)

Example

The following example shows how to use withZoneSameLocal.

import java.time.ZoneId;
import java.time.ZonedDateTime;
/*from  ww  w  . j ava 2  s.c  o  m*/
public class Main {
  public static void main(String[] args) {
    ZonedDateTime dateTime =ZonedDateTime.now();
    ZonedDateTime l =dateTime.withZoneSameLocal(ZoneId.systemDefault()) ;
    System.out.println(l);
  } 
}

The code above generates the following result.