OffsetDateTime atZoneSameInstant(ZoneId zone) example
Description
OffsetDateTime atZoneSameInstant(ZoneId zone)
combines this date-time with a time-zone
to create a ZonedDateTime ensuring that the result has the same instant.
Syntax
atZoneSameInstant
has the following syntax.
public ZonedDateTime atZoneSameInstant(ZoneId zone)
Example
The following example shows how to use atZoneSameInstant
.
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
/*from w ww .jav a 2 s . c om*/
public class Main {
public static void main(String[] args) {
OffsetDateTime o = OffsetDateTime.now();
ZonedDateTime d = o.atZoneSameInstant(ZoneId.systemDefault());
System.out.println(d);
}
}
The code above generates the following result.