java.time.LocalDateTime.ofEpochSecond() 方法示例



描述

java.time.LocalDateTime.ofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset) 方法使用 1970-01-01T00:00:00Z 的紀元中的秒數獲取 LocalDateTime 的例項。

宣告

以下是 java.time.LocalDateTime.ofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset) 方法的宣告。

public static LocalDateTime ofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset)

引數

  • epochSecond − 紀元 1970-01-01T00:00:00Z 中的秒數

  • nanoOfSecond − 秒中的納秒,從 0 到 999,999,999

  • offset − 時區偏移量,不能為空

返回值

LocalDateTime,不能為空。

異常

DateTimeException − 如果結果超出支援的範圍,或者納秒無效。

示例

以下示例展示了 java.time.LocalDateTime.ofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset) 方法的使用。

package com.tutorialspoint;

import java.time.LocalDateTime;
import java.time.ZoneOffset;

public class LocalDateTimeDemo {
   public static void main(String[] args) {
 
      LocalDateTime date = LocalDateTime.ofEpochSecond(50000,50000,ZoneOffset.UTC);
      System.out.println(date);  
   }
}

讓我們編譯並執行以上程式,將生成以下結果 −

1970-01-01T13:53:20.000050
廣告
© . All rights reserved.