java.time.ZoneId.from(TemporalAccessor temporal)
方法从temporal
对象获取ZoneId
的实例。
声明
以下是java.time.ZoneId.from(TemporalAccessor temporal)
方法的声明。
public static ZoneId from(TemporalAccessor temporal)
参数
temporal
- 要转换的时间对象,而不是null
。
返回值
本地日期,不为null
。
例外
DateTimeException
- 如果无法转换为ZoneId。
示例
以下示例显示了java.time.ZoneId.from(TemporalAccessor temporal)
方法的用法。
package com.yiibai;
import java.time.ZoneId;
import java.time.ZonedDateTime;
public class ZoneIdDemo {
public static void main(String[] args) {
ZoneId zone = ZoneId.from(ZonedDateTime.now());
System.out.println(zone);
}
}
编译并运行上面的程序,这将产生以下结果 -
Asia/Calcutta