在线Unix时间戳转换器 | 将时间戳转换为日期和时间

时间戳转换

当前Unix时间戳(秒)
时间戳

什么是Unix时间戳?

Unix时间戳(也称为纪元时间)是自1970年1月1日(UTC)以来经过的秒数。这是一种将时间作为累计秒数总和来跟踪的方法,使计算机处理和比较日期变得更容易。

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

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

在2038年1月19日03:14:07 UTC,32位系统将在Unix时间表示中遇到整数溢出,这被称为2038年问题。在此之后,除非这些系统被更新以使用更宽的时间戳格式,否则它们将无法正确编码时间。

在不同编程语言中获取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()