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.tutorialspoint;

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
廣告
© . All rights reserved.