import java.time.Instant;
public class UnixTimestampExample {
    public static void main(String[] args) {
        // 获取当前时间的Unix时间戳
        long currentTimestamp = Instant.now().getEpochSecond();
        System.out.println("当前的Unix时间戳: " + currentTimestamp);
        // 将Unix时间戳转换为可读日期时间
        Instant instant = Instant.ofEpochSecond(currentTimestamp);
        System.out.println("对应的日期时间: " + instant);
    }
}Instant.now().getEpochSecond() 返回自1970年1月1日(UTC)以来的秒数,这就是Unix时间戳。Instant.ofEpochSecond(currentTimestamp) 可以将Unix时间戳转换为 Instant 对象,进而可以输出更易读的日期时间格式。上一篇:java resultset
下一篇:java urlencode编码
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站