-
不同语言获取当前时间戳
Swift
NSDate().timeIntervalSince1970
Go
import (
"time"
)
int32(time.Now().Unix())
Java
// pure java
(int) (System.currentTimeMillis() / 1000)
// joda
(int) (DateTime.now().getMillis() / 1000)
JavaScript
Math.round(new Date() / 1000)
Objective-C
[[NSDate date] timeIntervalSince1970]
MySQL
SELECT unix_timestamp(now())
SQLite
SELECT strftime('%s', 'now')
Erlang
calendar:datetime_to_gregorian_seconds(calendar:universal_time())-719528*24*3600.
PHP
// pure php
time()
// Carbon\Carbon
Carbon::now()->timestamp
Python
import time
time.time()
Ruby
Time.now.to_i
Shell
date +%s
Groovy
(new Date().time / 1000).intValue()
Lua
os.time()
Perl
time
.NET/C#
(DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000
PostgreSQL
SELECT extract(epoch FROM now())
SQL Server
SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE())
Unix / Linux
date +%s
VBScript / ASP
DateDiff("s", "01/01/1970 00:00:00", Now())
不同语言转普通时间
Java
String date = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new
java.util.Date(Unix timestamp * 1000))
JavaScript
var unixTimestamp = new Date(Unix timestamp * 1000) 
commonTime = unixTimestamp.toLocaleString()
Objective-C
[[NSDate date] timeIntervalSince1970]
Linux
date -d @Unix timestamp
MySQL
from_unixtime(Unix timestamp)
Perl
my $time = Unix timestamp 
my ($sec, $min, $hour, $day, $month, $year) = (localtime($time))[0,1,2,3,4,5,6]
PHP
date('r', Unix timestamp)
PostgreSQL
SELECT TIMESTAMP WITH TIME ZONE 'epoch' + Unix timestamp) * INTERVAL '1
second';
Python
import time 
time.gmtime(Unix timestamp)
Ruby
Time.at(Unix timestamp)
SQL Server
DATEADD(s, Unix timestamp, '1970-01-01 00:00:00')
VBScript / ASP
DateAdd("s", Unix timestamp, "01/01/1970 00:00:00")
Unix时间戳

Unix时间戳(Unix timestamp),或称Unix时间(Unix time)、POSIX时间(POSIX time),是一种时间表示方式,定义为从格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总毫秒数。Unix时间戳不仅被使用在Unix系统、类Unix系统中(比如Linux系统),也在许多其他操作系统中被广泛采用。