现在:1591839643 控制: 停止

时间戳

时间 北京时间

各种编程语言获取当前时间戳

Swift
NSDate().timeIntervalSince1970
Go
import (
  "time"
)
int32(time.Now().Unix())
Java
(int) (System.currentTimeMillis() / 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
time()
Python
import time
time.time()
Ruby
Time.now.to_i
Shell
date +%s
Groovy
(new Date().time / 1000).intValue()

各种编程语言将时间戳转换为普通时间

Swift
Go
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
MySQL
from_unixtime(Unix timestamp)
SQLite
Erlang
PHP
date('r', Unix timestamp)
Python
import time
time.gmtime(Unix timestamp)
Ruby
Time.at(Unix timestamp)
Shell
Groovy