Javatime-instant-from

提供:Dev Guides
2020年6月23日 (火) 03:42時点におけるMaintenance script (トーク | 投稿記録)による版 (Imported from text file)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

java.time.Instant.from()メソッドの例

説明

  • java.time.Instant.from(TemporalAccessor temporal)*メソッドは、テンポラルオブジェクトからインスタントのインスタンスを取得します。

宣言

次に、* java.time.Instant.from(TemporalAccessor temporal)*メソッドの宣言を示します。

public static Instant from(TemporalAccessor temporal)

パラメーター

*temporal* -変換する一時オブジェクト、nullではない。

戻り値

インスタント、null以外。

例外

*DateTimeException* -インスタントに変換できない場合。

次の例は、java.time.Instant.from(TemporalAccessor temporal)メソッドの使用方法を示しています。

package com.finddevguides;

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