在 Ubuntu(Linux)系统中,获取“时间戳”通常指获取 Unix 时间戳(从 1970-01-01 00:00:00 UTC 到现在的秒数或毫秒数)。下面按常见场景说明。
date 命令(最常用)date +%s
示例输出:
1719301234
date(较新版本支持)date +%s%3N
pythonpython3 -c 'import time; print(int(time.time()*1000))'
date -d "2024-06-25 12:00:00" +%s
date -d "next monday" +%s
now=$(date +%s)
echo "当前时间戳: $now"
import time
print(time.time()) # 秒(浮点)
print(int(time.time())) # 秒(整数)
awk 'BEGIN {print systime()}'
date +%s 返回的是 UTC 时间戳,不受时区影响如果你是想:
可以告诉我具体场景,我可以给你更精准的方法。