Returns an instance of ZonedDateTime from an Instant and zone ID.
Returns an instance of ZonedDateTime from local date-time, an zone offset and zone ID. The combination of LocalDateTime and ZoneOffset, uniquely specifies an instant without ambiguity.
package com.logicbig.example.zoneddatetime;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
public class OfInstantExample {
public static void main(String... args) {
ZonedDateTime d = ZonedDateTime.ofInstant(Instant.parse("2007-12-03T10:15:30.00Z"),
ZoneId.systemDefault());
System.out.println(d);
}
}
Output
2007-12-03T04:15:30-06:00[America/Chicago]
package com.logicbig.example.zoneddatetime;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
public class OfInstantExample2 {
public static void main(String... args) {
ZonedDateTime d = ZonedDateTime.ofInstant(LocalDateTime.now(), ZoneOffset.ofHours(-5),
ZoneId.of("US/Central"));
System.out.println(d);
}
}
Output
2017-05-01T16:01:26.588-05:00[US/Central]