暂停

转换>>

转换>>

各语言获取当前时间戳

Java
(int) (System.currentTimeMillis() / 1000)
(int) (DateTime.now().getMillis() / 1000)
C
#include <sys/time.h>
struct timeval tv;
gettimeofday(&tv, NULL);
Python
import time
time.time()
.NET/C#
(DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000
JavaScript
Math.round(new Date() / 1000)
PHP
time()
// Carbon\Carbon
Carbon::now()->timestamp
Objective-C
[[NSDate date] timeIntervalSince1970]
MySQL
SELECT unix_timestamp(now())
Ruby
Time.now.to_i
Go
import (
  "time"
)
int32(time.Now().Unix())
Swift
NSDate().timeIntervalSince1970
SQLite
SELECT strftime('%s', 'now')
Erlang
calendar:datetime_to_gregorian_seconds(calendar:universal_time())-719528*24*3600.
Shell
date +%s
Groovy
(new Date().time / 1000).intValue()
Lua
os.time()