在线时间戳转换工具

时间戳转换

现在的 Unix 时间戳(秒)
时间戳

unix 时间戳是什么?

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

人类可读时间秒(s)
1 小时3600 秒
1 天86400 秒
1 周604800 秒
1 月 (30.44 天 )2629743 秒
1 年 (365.24 天 )31556926 秒

2038 年 1 月 19 日会发生什么?

由于 32 位溢出,此日 Unix 时间戳将停止工作。在此之前,数百万个应用程序需要采用新的时间戳约定,要么迁移到 64 位系统,这些系统将 “多一点” 购买时间戳。

不同编程语言中获取Unix时间戳

语言代码
JavaScript
Math.round(new Date() / 1000)
Python
import time time.time()
Ruby
Time.now.to_i
Go
import ('time') int64(time.Now().Unix())
Java(pure)
System.currentTimeMillis() / 1000
Java(joda)
DateTime.now().getMillis() / 1000
Java >= 8
Instant.now().getEpochSecond()
Swift
Date().timeIntervalSince1970
C
#include <sys/time.h> struct timeval tv; gettimeofday(&tv, NULL);
Objective-C
[[NSDate date] timeIntervalSince1970]
MySQL
SELECT unix_timestamp(now())
SQLite
SELECT strftime('%s', 'now')
PHP
<?php pure php time();
Erlang
calendar:datetime_to_gregorian_seconds(calendar:universal_time())-719528*24*3600.
Shell
date +%s
Groovy
(new Date().time / 1000).longValue()
Lua
os.time()
.NET/C#
DateTimeOffset.UtcNow.ToUnixTimeSeconds();
Dart
(new DateTime.now().millisecondsSinceEpoch / 1000).truncate()