时间戳转换器
时间戳转换器是一个在线工具,可以在Unix时间戳和可读日期之间进行转换。支持实时时间显示和双向转换。
功能
- 实时时间:显示当前Unix时间戳和日期时间
- 时间戳转日期:将Unix时间戳转换为可读日期格式
- 日期转时间戳:将日期时间转换为Unix时间戳
- 自动检测:自动识别秒和毫秒时间戳
- 一键复制:快速复制转换结果
什么是Unix时间戳?
Unix时间戳是自1970年1月1日00:00:00 UTC以来经过的秒数。它是一个简单的数字,广泛用于计算机系统中存储和处理日期时间。
时间戳格式
- 秒时间戳:10位数字(例如:1699999999)
- 毫秒时间戳:13位数字(例如:1699999999999)
秒时间戳:1699999999 → 2023-11-15 07:46:39
毫秒时间戳:1699999999999 → 2023-11-15 07:46:39.999
重要日期
| 事件 | Unix时间戳 | 日期 |
|---|---|---|
| Unix纪元 | 0 | 1970-01-01 00:00:00 |
| 10亿秒 | 1000000000 | 2001-09-09 01:46:40 |
| 20亿秒 | 2000000000 | 2033-05-18 03:33:20 |
| 2038年问题 | 2147483647 | 2038-01-19 03:14:07 |
编程示例
JavaScript
// 获取当前时间戳(毫秒)
const timestampMs = Date.now();
console.log(timestampMs); // 1699999999999
// 获取当前时间戳(秒)
const timestampSec = Math.floor(Date.now() / 1000);
console.log(timestampSec); // 1699999999
// 时间戳转日期
const date = new Date(1699999999 * 1000);
console.log(date.toLocaleString()); // 2023-11-15 07:46:39
// 日期转时间戳
const timestamp = Math.floor(new Date('2023-11-15').getTime() / 1000);
console.log(timestamp); // 1699999999
Python
import time
from datetime import datetime
# 获取当前时间戳
timestamp = int(time.time())
print(timestamp) # 1699999999
# 时间戳转日期
date = datetime.fromtimestamp(1699999999)
print(date.strftime('%Y-%m-%d %H:%M:%S')) # 2023-11-15 07:46:39
# 日期转时间戳
dt = datetime(2023, 11, 15, 7, 46, 39)
timestamp = int(dt.timestamp())
print(timestamp) # 1699999999
2038年问题
32位系统的Unix时间戳最大值为2,147,483,647(2038-01-19 03:14:07 UTC)。超过此值后,32位系统可能会出现错误。现代64位系统不受此限制。