当前时间 --

时间戳转换

获取时间戳

秒转天、小时、分钟、秒

示例代码:

获取时间戳
语言(language)代码(code)
Javalong epoch = System.currentTimeMillis() / 1000
JavaScriptMath.floor(new Date().getTime() / 1000)
PHPtime()
Pythonimport time; time.time()
RubyTime.now.to_i
Gotime.Now().Unix()
MySQLSELECT UNIX_TIMESTAMP(NOW())
PostgreSQLSELECT extract(epoch FROM now())
Unix/Linux Shelldate +%s
字符串转时间戳
语言(language)代码(code)
JavaScriptMath.floor(new Date("2026-05-23 01:04:03").getTime() / 1000)
PHPstrtotime("2026-05-23 01:04:03")
Pythoncalendar.timegm(time.strptime("2026-05-23 01:04:03", "%Y-%m-%d %H:%M:%S"))
MySQLSELECT UNIX_TIMESTAMP("2026-05-23 01:04:03")
Unix/Linux Shelldate +%s -d "2026-05-23 01:04:03"
时间戳转字符串
语言(language)代码(code)
JavaScriptnew Date(epoch * 1000)
PHPdate("Y-m-d H:i:s", $epoch)
Pythontime.strftime("%Y-%m-%d %H:%M:%S", time.localtime(epoch))
MySQLSELECT FROM_UNIXTIME(epoch)
Unix/Linux Shelldate -d @1779469841

什么是 Unix 时间戳?

Unix 时间戳(Unix time / POSIX time)是从 1970 年 1 月 1 日 00:00:00 UTC 开始累计的秒数,常用于后端接口、日志系统、数据库字段和跨时区时间计算。

单位数量
1 分钟60
1 小时3600
1 天86400
1 周604800
1 年(365.24 天)31556926