java.time.Instant.from(TemporalAccessor temporal)
方法從時態對象獲取Instant
的實例。
聲明
以下是java.time.Instant.from(TemporalAccessor temporal)
方法的聲明。
public static Instant from(TemporalAccessor temporal)
參數
temporal
- 要轉換的時間對象,而不是null
。
返回值
瞬間,不是null
。
異常
DateTimeException
- 如果無法轉換為Instant
。
示例
以下示例顯示了java.time.Instant.from(TemporalAccessor temporal)
方法的用法。
package com.zaixian;
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
上一篇:
java.time.Instant類
下一篇:
java.time.LocalDate類