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.
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]