java.time.Instant.ofEpochMilli()方法

java.time.Instant.ofEpochMilli(long epochMilli)方法使用1970-01-01T00:00:00Z的紀元中的毫秒來獲取Instant的實例。

聲明

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

public static Instant ofEpochMilli(long epochMilli)

參數

  • epochMilli - 從1970-01-01T00:00:00Z開始的毫秒數。

返回值

瞬間,不是null

例外

  • DateTimeException - 如果瞬間超過最大或最小瞬間。

示例

以下示例顯示了java.time.Instant.ofEpochMilli(long epochMilli)方法的用法。

package com.zaixian;

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

上一篇: java.time.Instant類 下一篇: java.time.LocalDate類