Close

Java Date Time - ZonedDateTime.withZoneSameLocal() Examples

Java Date Time Java Java API 


Class:

java.time.ZonedDateTime

java.lang.Objectjava.lang.Objectjava.time.ZonedDateTimejava.time.ZonedDateTimejava.time.temporal.TemporalTemporaljava.time.chrono.ChronoZonedDateTimeChronoZonedDateTimejava.io.SerializableSerializableLogicBig

Method:

public ZonedDateTime withZoneSameLocal(ZoneId zone)

Returns a copy of this ZonedDateTime representing the same local date-time but with the provided zone id. The returned value is not at the same instant as of the original one.

Examples


package com.logicbig.example.zoneddatetime;

import java.time.ZoneId;
import java.time.ZonedDateTime;

public class WithZoneSameLocalExample {

public static void main(String... args) {
ZonedDateTime d = ZonedDateTime.of(2017, 2, 12, 20, 33, 23, 2000,
ZoneId.systemDefault());
System.out.println(d);

ZonedDateTime d2 = d.withZoneSameLocal(ZoneId.of("Pacific/Fiji"));
System.out.println(d2);

ZonedDateTime d3 = d.withZoneSameInstant(ZoneId.of("Pacific/Fiji"));
System.out.println(d3);
}
}

Output

2017-02-12T20:33:23.000002-06:00[America/Chicago]
2017-02-12T20:33:23.000002+12:00[Pacific/Fiji]
2017-02-13T14:33:23.000002+12:00[Pacific/Fiji]




See Also