java.time.Instant.toEpochMilli()方法

java.time.Instant.toEpochMilli()方法将此瞬间转换为1970-01-01T00:00:00Z的纪元的毫秒数。

声明

以下是java.time.Instant.toEpochMilli()方法的声明。

public long toEpochMilli()

返回值

1970-01-01T00:00:00Z时代以来的毫秒数。

异常

  • ArithmeticException - 如果发生数字溢出。

例子

以下示例显示了java.time.Instant.toEpochMilli()方法的用法。

package com.zaixian;

import java.time.Instant;

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

      Instant instant = Instant.parse("2014-12-03T10:15:30.00Z");
      System.out.println(instant.toEpochMilli());
   }
}

编译并运行上面的程序,这将产生以下结果 -

1417601730000

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