Unix 时间戳转换器
将 Unix 时间戳转换为人类可读的日期,并支持反向转换
当前 Unix 时间戳
1774458438
Wed, 25 Mar 2026 17:07:18 GMT
什么是 Unix 时间戳?
Unix 时间戳(也称为 epoch 时间或 POSIX 时间)是自 1970 年 1 月 1 日 00:00:00 UTC 起经过的秒数。这个日期称为 Unix epoch。每过一秒,计数器加一,从而为每个时刻赋予一个唯一的整数表示。Unix 时间戳转换器在此整数与人类可读日期格式(如 ISO 8601、RFC 2822 或特定区域格式)之间进行转换。
Unix 时间戳是计算机中表示时间的标准方式。数据库将 created_at 和 updated_at 列存储为整数或毫秒时间戳。API 响应中的时间戳用于缓存头部(Expires、Last-Modified)、JWT 声明(iat、exp、nbf)以及事件日志。nginx、syslog 和应用框架生成的日志文件均使用 epoch 时间。该格式无歧义,因为它始终表示 UTC,无需处理时区或夏令时偏移。
手动在时间戳和日期之间转换容易出错。像 1711324800 这样的值从外观上看不出它代表的日期。本工具将 Unix 时间戳转换为可读日期,并支持反向转换。无论是读取 JWT exp 声明、调试数据库查询,还是检查日志时间戳,它都能自动识别 10 位(秒)和 13 位(毫秒)的值。
为什么使用这个时间戳转换器?
从日志、数据库或 API 响应中读取原始 Unix 时间戳,要么需要记住 epoch 计算方法,要么需要编写临时代码。本转换器在浏览器中即可完成转换,无需任何配置。无论是解码 JWT 过期时间、审查日志条目,还是设置数据库 TTL,结果一键即得。工具会自动检测输入是 10 位秒级时间戳还是 13 位毫秒级时间戳,无需手动除以 1000。所有处理在浏览器本地运行,数据不会离开您的设备,来自内部系统和敏感日志的时间戳保持私密。
时间戳转换器使用场景
Unix 时间戳参考表
下表列出了常见的 Unix 时间戳及其对应的日期,可用于快速验证、测试以及了解 32 位和 64 位时间戳的范围。
| 时间戳 | 日期(UTC) | 说明 |
|---|---|---|
| 0 | Jan 1, 1970 00:00:00 UTC | Unix epoch start |
| 86400 | Jan 2, 1970 00:00:00 UTC | Exactly 1 day |
| 946684800 | Jan 1, 2000 00:00:00 UTC | Y2K |
| 1000000000 | Sep 9, 2001 01:46:40 UTC | 10-digit milestone |
| 1234567890 | Feb 13, 2009 23:31:30 UTC | Ascending digits |
| 1700000000 | Nov 14, 2023 22:13:20 UTC | Recent 10-digit |
| 2000000000 | May 18, 2033 03:33:20 UTC | Next 10-digit milestone |
| 2147483647 | Jan 19, 2038 03:14:07 UTC | Y2038 (signed 32-bit max) |
| 4102444800 | Jan 1, 2100 00:00:00 UTC | Next century |
日期与时间格式对比
不同系统和标准使用不同的字符串格式表示同一时刻。下表对比了 API、日志和数据库中最常见的格式。
| 格式 | 示例 | 说明 |
|---|---|---|
| Unix (seconds) | 1711324800 | Integer, no timezone info |
| Unix (milliseconds) | 1711324800000 | Used by JavaScript Date.now() |
| ISO 8601 | 2024-03-25T00:00:00Z | Machine-readable, includes timezone |
| RFC 2822 | Mon, 25 Mar 2024 00:00:00 +0000 | Email and HTTP headers |
| UTC string | Mon, 25 Mar 2024 00:00:00 GMT | Date.prototype.toUTCString() |
| Human readable | March 25, 2024, 12:00:00 AM | Locale-dependent, display only |
代码示例
在您使用的编程语言中实现 Unix 时间戳与日期之间的转换。每个示例均展示两个方向:时间戳转日期和日期转时间戳。
// Current Unix timestamp in seconds
Math.floor(Date.now() / 1000) // → 1711324800
// Unix timestamp to Date object
const date = new Date(1711324800 * 1000)
date.toISOString() // → "2024-03-25T00:00:00.000Z"
date.toUTCString() // → "Mon, 25 Mar 2024 00:00:00 GMT"
// Date string to Unix timestamp
Math.floor(new Date('2024-03-25T00:00:00Z').getTime() / 1000)
// → 1711324800
// Millisecond timestamps (common in JS APIs)
Date.now() // → 1711324800000 (ms)
Date.parse('2024-03-25') // → 1711324800000 (ms)import time
from datetime import datetime, timezone
# Current Unix timestamp
int(time.time()) # → 1711324800
# Unix timestamp to datetime
dt = datetime.fromtimestamp(1711324800, tz=timezone.utc)
dt.isoformat() # → '2024-03-25T00:00:00+00:00'
dt.strftime('%Y-%m-%d %H:%M:%S %Z') # → '2024-03-25 00:00:00 UTC'
# Datetime string to Unix timestamp
dt = datetime.fromisoformat('2024-03-25T00:00:00+00:00')
int(dt.timestamp()) # → 1711324800
# Parse RFC 2822 dates (from email headers)
from email.utils import parsedate_to_datetime
parsedate_to_datetime('Mon, 25 Mar 2024 00:00:00 +0000').timestamp()
# → 1711324800.0package main
import (
"fmt"
"time"
)
func main() {
// Current Unix timestamp
now := time.Now().Unix() // → 1711324800
// Unix timestamp to time.Time
t := time.Unix(1711324800, 0).UTC()
fmt.Println(t.Format(time.RFC3339))
// → 2024-03-25T00:00:00Z
// Parse a date string to Unix timestamp
parsed, _ := time.Parse(time.RFC3339, "2024-03-25T00:00:00Z")
fmt.Println(parsed.Unix())
// → 1711324800
// Millisecond timestamp
ms := time.Now().UnixMilli() // → 1711324800000
fmt.Println(now, ms)
}# Current Unix timestamp date +%s # → 1711324800 # Convert timestamp to human-readable date (GNU date) date -d @1711324800 # → Mon Mar 25 00:00:00 UTC 2024 # Convert timestamp to ISO 8601 date -d @1711324800 --iso-8601=seconds # → 2024-03-25T00:00:00+00:00 # macOS (BSD date) — slightly different flags date -r 1711324800 # → Mon Mar 25 00:00:00 UTC 2024 # Date string to timestamp (GNU date) date -d "2024-03-25 00:00:00 UTC" +%s # → 1711324800