当前时间戳(秒级)
--
--
北京时间 (UTC+8) · 毫秒级: --
已复制到剪贴板
转换结果
--
ISO 8601
--
UTC时间
--
本地时间
--
相对时间
--
转换结果
--
秒级时间戳
--
毫秒级时间戳
--
微秒级时间戳
--
ISO 8601
--

Unix时间戳是什么?

Unix时间戳是从1970年1月1日00:00:00 UTC开始到某个时间点所经过的秒数(或毫秒数)。它是一种与时区无关的纯数字表示方式,广泛用于计算机系统、数据库、API接口等。

基本原理 时间戳 (秒) = 目标时间 - 1970-01-01 00:00:00 UTC
本地时间 = UTC时间 + 时区偏移(北京时间 +8 小时)

示例:时间戳 1717142400 对应 UTC 时间 2024-05-31 04:00:00,转为北京时间(+8小时)后为 2024-05-31 12:00:00。

秒、毫秒、微秒的区别

  • 秒级(10位):最常用,如 Java System.currentTimeMillis()/1000
  • 毫秒级(13位):JavaScript 原生 Date.now() 输出,精度更高
  • 微秒级(16位):高性能计时、科学计算场景

判断技巧:数数位数。10位是秒,13位是毫秒,16位是微秒。

各编程语言获取时间戳

JavaScript// 秒级
const ts = Math.floor(Date.now() / 1000);
// 毫秒级
const ms = Date.now();
Pythonimport time
ts = int(time.time()) # 秒级
Java// 秒级
long ts = System.currentTimeMillis() / 1000;
// 毫秒级
long ms = System.currentTimeMillis();

其他语言示例请切换至英文版查看。

常见问题

时间戳会用完吗?2038年问题是什么?

32位系统存储秒级时间戳的最大值是 2,147,483,647,对应2038年1月19日 03:14:07 UTC。超过这个时间会溢出。现代64位系统已彻底解决此问题。

为什么我的时间戳转换结果差了8小时?

时间戳是UTC时间,转换为本地时间时需要加上时区偏移。北京时间(UTC+8)会比UTC多8小时。若结果少了8小时,可能是以UTC格式显示的。

JavaScript的Date.now()为什么是13位?

JavaScript内建使用毫秒级精度。若需要秒级,可除以1000并取整:Math.floor(Date.now() / 1000)。反过来传递给Date对象时也要乘回1000。

ISO 8601格式有什么用?

ISO 8601是国际标准化组织规定的时间表示法,各编程语言和系统通用。其形式如 2024-05-31T12:00:00.000+08:00,末尾的+08:00表示东八区。

Current Timestamp (seconds)
--
--
Local Time · Milliseconds: --
Copied to clipboard
Result
--
ISO 8601
--
UTC Time
--
Local Time
--
Relative
--
Result
--
Seconds
--
Milliseconds
--
Microseconds
--
ISO 8601
--

What is a Unix Timestamp?

A Unix timestamp is the number of seconds (or milliseconds) since January 1, 1970, 00:00:00 UTC. It is a timezone-independent way to represent a point in time.

How It Works Timestamp (seconds) = Target Time − 1970‑01‑01 00:00:00 UTC
Local Time = UTC + timezone offset

Seconds vs Milliseconds vs Microseconds

  • 10 digits: seconds
  • 13 digits: milliseconds (JavaScript native)
  • 16 digits: microseconds (high‑precision)

Code Examples

JavaScriptconst ts = Math.floor(Date.now() / 1000);
Pythonimport time
ts = int(time.time())
Gots := time.Now().Unix()

FAQ

Will timestamps run out?

32‑bit timestamps overflow in 2038. 64‑bit systems resolve this.

Why are my results off by 8 hours?

Timestamps are UTC. Convert to your local timezone by adding the offset. China uses UTC+8.

Why is JavaScript Date.now() 13 digits?

JavaScript uses millisecond precision. Divide by 1000 for seconds.