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类