java.time.OffsetDateTime.toEpochSecond() 方法示例



描述

java.time.OffsetDateTime.toEpochSecond() 方法將此日期時間轉換為從 1970-01-01T00:00:00Z 起的秒數。

宣告

以下是 java.time.OffsetDateTime.toEpochSecond() 方法的宣告。

public long toEpochSecond()

返回值

從 1970-01-01T00:00:00Z 起的秒數。

示例

以下示例顯示了 java.time.OffsetDateTime.toEpochSecond() 方法的使用。

package com.tutorialspoint;

import java.time.OffsetDateTime;

public class OffsetDateTimeDemo {
   public static void main(String[] args) {
 
      OffsetDateTime date = OffsetDateTime.now();
      System.out.println(date.toEpochSecond());  
   }
}

讓我們編譯並執行上述程式,這將產生以下結果 -

1490085824
廣告
© . All rights reserved.