java.time.Instant.ofEpochMilli() 方法示例



描述

java.time.Instant.ofEpochMilli(long epochMilli) 方法獲取一個即時,它使用的是自 1970-01-01T00:00:00Z 以來的毫秒數。

宣告

以下是 java.time.Instant.ofEpochMilli(long epochMilli) 方法的宣告。

public static Instant ofEpochMilli(long epochMilli)

引數

epochMilli − 自 1970-01-01T00:00:00Z 以來的毫秒數。

返回值

即時,非空。

異常

DateTimeException − 如果即時超過最大或最小即時。

示例

以下示例顯示瞭如何使用 java.time.Instant.ofEpochMilli(long epochMilli) 方法。

package com.tutorialspoint;

import java.time.Instant;

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

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

讓我們編譯並執行以上程式,這將產生以下結果 −

1970-01-01T00:00:10Z
廣告
© . All rights reserved.