// 获取秒级时间戳的示例代码
import java.time.Instant;
public class TimestampExample {
public static void main(String[] args) {
// 获取当前时间的秒级时间戳
long timestamp = Instant.now().getEpochSecond();
// 打印秒级时间戳
System.out.println("当前秒级时间戳: " + timestamp);
}
}
Instant.now()
:获取当前时间的 Instant
对象,表示精确到纳秒的时间点。getEpochSecond()
:从 Instant
对象中提取秒级时间戳,返回自1970年1月1日00:00:00 UTC(Unix纪元)以来的秒数。System.out.println
:将获取到的秒级时间戳打印输出。这段代码展示了如何在Java中获取并打印当前时间的秒级时间戳。
上一篇:java list 删除元素
下一篇:java中substring
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站