static LocalDateTime ofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset)
描述 (Description)
java.time.LocalDateTime.ofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset)方法使用1970-01-01T00:00:00Z的纪元中的秒获得LocalDateTime的实例。
声明 (Declaration)
以下是java.time.LocalDateTime.ofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset)方法的声明。
public static LocalDateTime ofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset)
参数 (Parameters)
epochSecond - 1970-01-01T00:00:00Z时代的秒数
nanoOfSecond - 秒内的纳秒,从0到999,999,999
offset - 区域偏移量,不为空
返回值 (Return Value)
本地日期时间,不为空。
异常 (Exceptions)
DateTimeException - 如果结果超出支持的范围,或者纳秒级无效。
例子 (Example)
以下示例显示了java.time.LocalDateTime.ofEpochSecond(long epochSecond,int nanoOfSecond,ZoneOffset offset)方法的用法。
package com.iowiki;
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