正常日期时间和Unix时间戳转换器,为程序猿同学提供了多种编程语言里获取当前时间戳的方法
编程语言 | 获取时间戳的函数/方法 |
---|---|
Java | time |
PHP | 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 |
Golang | time.Now().Unix() |
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) |
Copyright © 2018 - 2024 在线工具. All rights reserved