java.time.Instant.atZone(ZoneId zone)
方法将此瞬间与时区组合以创建ZonedDateTime。
声明
以下是java.time.Instant.atZone(ZoneId zone)
方法的声明。
public ZonedDateTime atZone(ZoneId zone)
参数
zone
- 要与之结合的区域,而不是null
。
返回值
从此瞬间和指定区域形成的分区日期时间,不为null
。
异常
DateTimeException
- 如果结果超出支持的范围。
示例
以下示例显示了java.time.Instant.atZone(ZoneId zone)
方法的用法。
package com.zaixian;
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]
上一篇:
java.time.Instant类
下一篇:
java.time.LocalDate类