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



描述

java.time.Instant.getEpochSecond() 方法獲取 1970-01-01T00:00:00Z 的 Java 起始時間相差的秒數。

申明

以下是 java.time.Instant.getEpochSecond() 方法的申明。

public long getEpochSecond()

返回值

從 1970-01-01T00:00:00Z 起始時間相差的秒數。

示例

以下示例展示了 java.time.Instant.getEpochSecond() 方法的使用。

package com.tutorialspoint;

import java.time.Instant;

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

      Instant instant = Instant.parse("2017-03-03T10:37:30.00Z");
      System.out.println(instant.getEpochSecond());
   }
}

當我們編譯並執行以上程式時,會產生以下結果 −

1488537450
廣告
© . All rights reserved.