ZonedDateTime withZoneSameLocal(ZoneId zone) example
Description
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 w w w. j a v a2s. c om*/
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.