Javatime-instant-ofepochsecond

提供:Dev Guides
移動先:案内検索

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

説明

  • java.time.Instant.ofEpochSecond(long epochSecond)*メソッドは、1970-01-01T00:00:00Zのエポックからの秒数を使用してInstantのインスタンスを取得します。

宣言

以下は、* java.time.Instant.ofEpochSecond(long epochSecond)*メソッドの宣言です。

public static Instant ofEpochSecond(long epochSecond)

パラメーター

*epochSecond* -1970-01-01T00:00:00Zからの秒数。

戻り値

インスタント、nullではない。

例外

*DateTimeException* -インスタントが最大または最小インスタントを超える場合。

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

package com.finddevguides;

import java.time.Instant;

public class InstantDemo {
   public static void main(String[] args) {

      Instant instant = Instant.ofEpochSecond(10000);
      System.out.println(instant);
   }
}

上記のプログラムをコンパイルして実行すると、次の結果が生成されます-

1970-01-01T02:46:40Z