Javatime-instant-ofepochsecond1

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

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

説明

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

宣言

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

public static Instant ofEpochSecond(long epochSecond, long nanoAdjustment)

パラメーター

  • epochSecond -1970-01-01T00:00:00Zからの秒数。
  • nanoAdjustment -秒数に対するナノ秒の調整、正または負。

戻り値

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

例外

  • DateTimeException -インスタントが最大または最小インスタントを超える場合。
  • ArithmeticException -数値オーバーフローが発生した場合。

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

package com.finddevguides;

import java.time.Instant;

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

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

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

1970-01-01T02:46:40.000001Z