ToolPal
Close-up of a sleek digital clock displaying time, set on a contemporary wooden surface near electronics.

Unix时间戳详解 - 什么是Unix时间戳以及如何转换

📷 FOX ^.ᆽ.^= ∫ / Pexels

Unix时间戳详解 - 什么是Unix时间戳以及如何转换

了解Unix时间戳:它是什么、如何工作以及如何将其转换为可读日期。开发者必备的基础知识。

D作者: Daniel Park2026年3月10日1分钟阅读

什么是Unix时间戳?

Unix时间戳(也称为Epoch时间或POSIX时间)是自1970年1月1日00:00:00 UTC以来经过的秒数。这个日期被称为「Unix纪元」。

示例

  • 0 = 1970年1月1日 00:00:00 UTC
  • 1000000000 = 2001年9月9日 01:46:40 UTC
  • 1710547200 = 2024年3月16日 00:00:00 UTC

为什么使用Unix时间戳?

  1. 通用性 — 没有时区困扰。时间戳在任何地方都表示相同的含义
  2. 可排序 — 简单的数值比较即可排序事件
  3. 紧凑 — 一个整数就够了,不需要格式化的日期字符串
  4. 语言无关 — 每种编程语言都能处理整数

常用操作

JavaScript

// 当前时间戳(秒)
Math.floor(Date.now() / 1000);

// 时间戳转Date
new Date(timestamp * 1000);

// Date转时间戳
Math.floor(new Date('2026-03-16').getTime() / 1000);

Python

import time
from datetime import datetime

# 当前时间戳
time.time()

# 时间戳转datetime
datetime.fromtimestamp(1710547200)

# datetime转时间戳
datetime(2026, 3, 16).timestamp()

2038年问题

存储为32位有符号整数的Unix时间戳将在2038年1月19日溢出。现代系统使用64位整数,在未来2920亿年内不会溢出。

毫秒 vs 秒

  • Unix时间戳(秒)1710547200(10位数)
  • JavaScript时间戳(毫秒)1710547200000(13位数)

如果时间戳有13位数,说明它是毫秒单位的。除以1000即可得到秒。

立即转换时间戳

使用我们的免费Unix时间戳转换工具在Unix时间戳和可读日期之间即时转换。

常见问题

D

关于作者

Daniel Park

Senior frontend engineer based in Seoul. Seven years of experience building web applications at Korean SaaS companies, with a focus on developer tooling, web performance, and privacy-first architecture. Open-source contributor to the JavaScript ecosystem and founder of ToolPal.

了解更多

分享文章

XLinkedIn

相关文章