static Instant from(TemporalAccessor temporal)
描述 (Description)
java.time.Instant.from(TemporalAccessor temporal)方法从时态对象获取Instant的实例。
声明 (Declaration)
以下是java.time.Instant.from(TemporalAccessor temporal)方法的声明。
public static Instant from(TemporalAccessor temporal)
参数 (Parameters)
temporal - 要转换的时间对象,而不是null。
返回值 (Return Value)
瞬间,不是空的。
异常 (Exceptions)
DateTimeException - 如果无法转换为Instant。
例子 (Example)
以下示例显示了java.time.Instant.from(TemporalAccessor temporal)方法的用法。
package com.iowiki;
import java.time.Instant;
import java.time.ZonedDateTime;
public class InstantDemo {
public static void main(String[] args) {
ZonedDateTime zonedDateTime = ZonedDateTime.now();
Instant instant = Instant.from(zonedDateTime);
System.out.println(instant);
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
2017-03-10T09:29:03.044Z