温馨提示×

java如何打印时间戳

小亿
112
2024-07-27 02:51:07
栏目: 编程语言

在Java中,可以使用System.currentTimeMillis()方法来打印当前时间戳。示例如下:

public class Main {
    public static void main(String[] args) {
        long timestamp = System.currentTimeMillis();
        System.out.println("当前时间戳:" + timestamp);
    }
}

运行该代码会打印出当前时间戳,单位为毫秒。如果需要以其他格式显示时间戳,可以使用SimpleDateFormat类将时间戳转换为特定格式的日期和时间。

0