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 - 對秒數的納秒級調整,正值或負值。

返回值

一個 Instant,非空。

異常

  • DateTimeException - 如果 Instant 超出最大或最小 Instant。

  • ArithmeticException - 如果發生數字上溢。

示例

以下示例展示瞭如何使用 java.time.Instant.ofEpochSecond(long epochSecond, long nanoAdjustment) 方法。

package com.tutorialspoint;

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
廣告
© . All rights reserved.