工具箱 返回主站

Unix 时间戳转换

时间戳与日期时间双向转换 · 自动识别秒 / 毫秒 · 基于浏览器本地时区

当前时间戳

—
秒(s)
—
毫秒(ms)
本地时间—
时区— 偏移—
UTC 时间—

时间戳 → 日期时间

本地时间
—
UTC 时间
—
ISO 8601
—
星期
—
相对现在
—
自动模式下:位数 ≥ 12 位按毫秒解析,否则按秒解析;支持负数(1970 年之前)。

日期时间 → 时间戳

时间戳(秒)
—
时间戳(毫秒)
—
ISO 8601
—
UTC 时间
—
相对现在
—
支持 2023-11-15 06:13:20、2023-11-15 06:13、2023-11-15、2023/11/15 等写法,按浏览器本地时区解析。

各语言获取当前时间戳

JavaScript Math.floor(Date.now() / 1000)
PHP time()
Python import time; int(time.time())
Java System.currentTimeMillis() / 1000
Go time.Now().Unix()
C / C++ time(NULL)
C# DateTimeOffset.UtcNow.ToUnixTimeSeconds()
MySQL SELECT UNIX_TIMESTAMP()
SQLite strftime('%s', 'now')
Shell date +%s
Ruby Time.now.to_i
Swift Int(Date().timeIntervalSince1970)
Objective-C (long)[[NSDate date] timeIntervalSince1970]
Lua os.time()
Erlang erlang:system_time(second)
Dart DateTime.now().millisecondsSinceEpoch ~/ 1000
Groovy (new Date().time / 1000).longValue()
.NET DateTimeOffset.UtcNow.ToUnixTimeSeconds()

· Unix 时间戳是从 1970 年 1 月 1 日 00:00:00 UTC 起经过的秒数(不考虑闰秒),0 即表示 1970-01-01 00:00:00 UTC。

· 秒与毫秒相差 1000 倍:常见的 10 位数字是秒,13 位数字是毫秒,本工具可自动识别。

· 日期与时间均按浏览器所在时区换算,页面顶部会显示当前检测到的时区与 UTC 偏移。

· 全部换算在浏览器本地即时完成,输入时即出结果,不上传任何数据。