// 获取当前时间戳的示例代码
import java.time.Instant;
public class CurrentTimestamp {
public static void main(String[] args) {
// 获取当前时间戳(以秒为单位)
long currentTimestampInSeconds = Instant.now().getEpochSecond();
System.out.println("当前时间戳(秒): " + currentTimestampInSeconds);
// 获取当前时间戳(以毫秒为单位)
long currentTimestampInMilliseconds = System.currentTimeMillis();
System.out.println("当前时间戳(毫秒): " + currentTimestampInMilliseconds);
}
}
Instant.now().getEpochSecond()
:获取当前时间戳,以秒为单位。它返回自1970年1月1日00:00:00 UTC以来的秒数。System.currentTimeMillis()
:获取当前时间戳,以毫秒为单位。它返回自1970年1月1日00:00:00 UTC以来的毫秒数。这两种方法都可以用来获取当前的时间戳,具体使用哪种取决于你的需求。
上一篇:java list遍历
下一篇:java解析xml字符串
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站