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)

java.time.Instant java.time.Instant.ofEpochSecond(long epochSecond)

引數

epochSecond - 從 1970-01-01T00:00:00Z 起的秒數。

返回值

一個 instant,非空。

異常

DateTimeException - 如果 instant 超過最大或最小 instant。

示例

package com.tutorialspoint;

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
列印頁面
© . All rights reserved.