Unix时间戳转换

当前Unix时间戳(基于浏览器时间):

知识科普

Unix时间戳

Unix 时间戳是从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数,不考虑闰秒。

Unix 时间戳(英文为 Unix epoch, Unix time, POSIX time 或 Unix timestamp)

例如:一个小时表示为Unix时间戳为 3600 秒;一天表示为Unix时间戳为 86400 秒,闰秒不计算。

时间戳对照表
  • 1 分钟 = 60 秒
  • 1 小时 = 3600 秒
  • 1 天 = 86400 秒
  • 1 周 = 604800 秒
  • 1 月 (30.44 天) = 2629743 秒
  • 1年 (365.24 天) = 31556736 秒
语言名称 获取时间戳的函数或方法
PHP time()
Golang time.Now().Unix()
Java time
JavaScript Math.round(new Date().getTime()/1000)
MySQL SELECT unix_timestamp(now())
PostgreSQL SELECT extract(epoch FROM now())
SQLite SELECT strftime('%s', 'now')
SQL Server SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE())
Python first import time, then time.time()
Microsoft .NET / C# epoch = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000
Perl time
Ruby Time.now or Time.new
Lua epoch = os.time([date])
R as.numeric(Sys.time())
PowerShell [int][double]::Parse((Get-Date (get-date).touniversaltime() -UFormat %s))
Unix / Linux date +%s
VBScript / ASP DateDiff("s", "01/01/1970 00:00:00", Now())
C / C++ time(NULL)
Objective-C [[NSDate date] timeIntervalSince1970]
Swift now.timeIntervalSince1970
Delphi DateTimeToUnix(Now)