java.time.Instant.atZone() 方法
描述
java.time.Instant.atZone(ZoneId zone) 方法将此瞬间与时区结合起来创建 ZonedDateTime。
声明
以下是 java.time.Instant.atZone(ZoneId zone) 方法的声明。
public ZonedDateTime atZone(ZoneId zone)
参数
zone − 要结合的区域,不为空。
返回值
从这一时刻和指定区域形成的分区日期时间,不为空。
异常
DateTimeException − 如果结果超出支持的范围。
示例
下面的例子展示了 java.time.Instant.atZone(ZoneId zone) 方法的使用。
package com.tutorialspoint;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Set;
public class InstantDemo {
public static void main(String[] args) {
Instant instant = Instant.parse("2017-02-03T10:37:30.00Z");
System.out.println(instant);
Set<String> zones = ZoneId.getAvailableZoneIds();
ZoneId zone = ZoneId.of(zones.iterator().next());
ZonedDateTime date = instant.atZone(zone);
System.out.println(date);
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
2017-02-03T10:37:30Z 2017-02-03T13:37:30+03:00[Asia/Aden]

