Unix 时间戳转换器
这个 Unix 时间戳转换器可在 Unix 纪元时间戳和人类可读日期之间相互转换。输入时间戳或日期,即可查看对应的转换结果,支持毫秒精度和多时区显示。
Current Unix Timestamp
--
Milliseconds: --
Frequently Asked Questions
什么是Unix时间戳?
Unix时间戳(也称为Unix时间、POSIX时间或纪元时间)是自1970年1月1日00:00:00 UTC(即Unix纪元)以来经过的秒数。它提供了一种简单、与时区无关的方式,将特定时刻表示为单个整数。例如,时间戳1700000000代表2023年11月14日22:13:20 UTC。
如何将Unix时间戳转换为日期?
要将Unix时间戳转换为人类可读的日期,将时间戳乘以1000(如果以秒为单位)得到毫秒,然后创建日期对象。在JavaScript中:new Date(timestamp * 1000)。在Python中:datetime.fromtimestamp(timestamp)。我们的转换器自动处理此操作,并以多种格式显示结果,包括ISO 8601、RFC 2822和本地时间。
什么是纪元时间?
纪元时间是指计算系统中计时的起点。Unix纪元是1970年1月1日00:00:00 UTC。这个日期是在Unix于20世纪70年代初开发时选择的方便参考点。所有Unix时间戳都计算为自此纪元以来经过的秒数,使其成为跨系统的通用时间参考。
为什么Unix时间从1970年开始?
Unix时间从1970年1月1日开始,因为贝尔实验室的早期Unix开发人员选择该日期作为方便、最近的参考点。原始Unix系统是在20世纪60年代末开发的,1970年是接近系统创建日期的整数。使用固定纪元使时间计算变得简单:只需从这个参考点加减秒数。
什么是2038年问题?
2038年问题(Y2K38)发生是因为许多系统将Unix时间戳存储为32位有符号整数,最大值为2,147,483,647。这对应于2038年1月19日03:14:07 UTC。在这一时刻之后,整数溢出并变为负数,被解释为1901年12月13日。大多数现代系统现在使用64位整数,将范围延伸到约2920亿年。
如何获取当前Unix时间戳?
在JavaScript中:Math.floor(Date.now() / 1000)。在Python中:import time; int(time.time())。在PHP中:time()。在Bash中:date +%s。在Java中:System.currentTimeMillis() / 1000。这些都返回自Unix纪元以来的当前秒数。注意,JavaScript中的Date.now()返回毫秒,因此除以1000得到标准的基于秒的时间戳。
Unix时间戳的秒和毫秒有什么区别?
以秒为单位的Unix时间戳是10位数字(例如1700000000),计算自纪元以来的秒数。毫秒时间戳是13位数字(例如1700000000000),计算自纪元以来的毫秒数。JavaScript的Date.now()返回毫秒,而大多数服务器端语言使用秒。转换方法:毫秒 = 秒 × 1000,秒 = 毫秒 / 1000。
10位和13位Unix时间戳有什么区别?
10位Unix时间戳表示自1970年1月1日以来的秒数(例如,1710936000 = 2024年3月20日)。13位时间戳表示毫秒(例如,1710936000000 = 同一时刻,具有毫秒精度)。大多数编程语言和数据库使用秒(10位),而JavaScript的Date.now()返回毫秒(13位)。本转换器根据位数自动检测格式。
如何在Excel中转换Unix时间戳?
要在Excel中将Unix时间戳转换为日期,使用公式:=(A1/86400)+DATE(1970,1,1),其中A1包含以秒为单位的时间戳。对于毫秒,使用:=(A1/86400000)+DATE(1970,1,1)。将单元格格式设置为日期/时间以查看可读结果。将日期转换回Unix时间戳:=(A1-DATE(1970,1,1))*86400。注意,Excel日期基于您的本地时区,因此结果可能因时区偏移而与UTC不同。
Unix时间戳可以是负数吗?
是的,负Unix时间戳表示1970年1月1日(Unix纪元)之前的日期。例如,-86400表示1969年12月31日(纪元前一天)。大多数编程语言完全支持负时间戳:Python的datetime.fromtimestamp(-86400)返回1969-12-31。这对历史日期很有用,尽管非常早的日期(约1901年之前)可能超出32位有符号整数的范围。
Unix Timestamp Converter Guide
What Is a Unix Timestamp?
A Unix timestamp (also known as Epoch time or POSIX time) is the number of seconds that have elapsed since January 1, 1970 00:00:00 UTC, not counting leap seconds. This date is known as the Unix epoch. Unix timestamps are widely used in computing because they provide a simple, unambiguous way to represent a specific moment in time regardless of time zone.
How to Use This Tool
Timestamp to Date:
- Enter a Unix timestamp in seconds (10 digits) or milliseconds (13 digits)
- The tool auto-detects whether the input is in seconds or milliseconds
- Click "Now" to populate with the current timestamp
- Results are shown in multiple formats for convenience
Date to Timestamp:
- Select a date using the date picker
- Optionally set a specific time
- The corresponding Unix timestamp is shown in both seconds and milliseconds
Output Formats
- ISO 8601: The international standard format, e.g.,
2024-01-15T10:30:00.000Z - RFC 2822: Common email and HTTP header format, e.g.,
Mon, 15 Jan 2024 10:30:00 GMT - Local Time: Formatted according to your browser's locale settings
- UTC: Universal Coordinated Time representation
Seconds vs. Milliseconds
Unix timestamps can be represented in two common units:
- Seconds (10 digits): The traditional Unix format used by most command-line tools and server-side languages (e.g.,
1700000000) - Milliseconds (13 digits): Used by JavaScript (
Date.now()), Java, and many APIs (e.g.,1700000000000)
This converter automatically detects which unit your input uses based on the number of digits.
Common Timestamps
| Timestamp | Date |
|---|---|
| 0 | January 1, 1970 00:00:00 UTC (Unix Epoch) |
| 1000000000 | September 9, 2001 01:46:40 UTC |
| 1700000000 | November 14, 2023 22:13:20 UTC |
| 2000000000 | May 18, 2033 03:33:20 UTC |
| 2147483647 | January 19, 2038 03:14:07 UTC (Y2K38 problem) |
Use Cases
- Debugging API responses that return timestamps
- Converting log file timestamps to human-readable dates
- Setting up scheduled tasks (cron jobs) with specific timestamps
- Working with databases that store dates as Unix timestamps
- Comparing dates across different time zones without ambiguity
Unix Timestamp in Programming Languages
Here are examples of how to get the current Unix timestamp and convert a timestamp to a date in popular programming languages:
Python
import time
import datetime
# Get current Unix timestamp
timestamp = int(time.time())
# Convert timestamp to date
dt = datetime.datetime.fromtimestamp(timestamp)
print(dt) # e.g., 2026-03-20 12:00:00JavaScript
// Get current Unix timestamp (seconds)
const timestamp = Math.floor(Date.now() / 1000);
// Convert timestamp to date
const date = new Date(timestamp * 1000);
console.log(date.toISOString());PHP
// Get current Unix timestamp
$timestamp = time();
// Convert timestamp to date
echo date('Y-m-d H:i:s', $timestamp);Java
import java.time.Instant;
import java.time.ZoneId;
import java.time.LocalDateTime;
// Get current Unix timestamp
long timestamp = System.currentTimeMillis() / 1000;
// Convert timestamp to date
LocalDateTime dt = Instant.ofEpochSecond(timestamp)
.atZone(ZoneId.systemDefault())
.toLocalDateTime();SQL (MySQL)
-- Get current Unix timestamp
SELECT UNIX_TIMESTAMP();
-- Convert timestamp to date
SELECT FROM_UNIXTIME(1710936000);
-- Result: '2024-03-20 12:00:00'Go
package main
import (
"fmt"
"time"
)
// Get current Unix timestamp
ts := time.Now().Unix()
// Convert timestamp to date
t := time.Unix(ts, 0)
fmt.Println(t.Format("2006-01-02 15:04:05"))Bash
# Get current Unix timestamp
date +%s
# Convert timestamp to date (Linux)
date -d @1710936000
# Convert timestamp to date (macOS)
date -r 1710936000Common Unix Timestamp Values
A quick reference table of notable Unix timestamps for developers:
| Date | Unix Timestamp (seconds) |
|---|---|
| January 1, 1970 (Unix Epoch) | 0 |
| January 1, 2000 (Y2K) | 946684800 |
| January 1, 2025 | 1735689600 |
| January 1, 2026 | 1767225600 |
| January 1, 2027 | 1798761600 |
| September 9, 2001 (1 billion) | 1000000000 |
| November 20, 2286 (10 billion) | 10000000000 |
| January 19, 2038 (Y2K38 overflow) | 2147483647 |
The Year 2038 Problem (Y2K38)
The Year 2038 Problem, often called Y2K38, is a computing limitation caused by storing Unix timestamps as 32-bit signed integers. A signed 32-bit integer can hold a maximum value of 2,147,483,647, which corresponds to January 19, 2038 at 03:14:07 UTC. One second after this moment, the integer overflows and wraps around to a negative number, which would be interpreted as a date in December 1901.
This problem is similar to the Y2K bug that affected systems at the turn of the millennium. However, Y2K38 is potentially more impactful because Unix timestamps are deeply embedded in operating systems, file systems, databases, and network protocols.
Modern systems have largely mitigated this issue by adopting 64-bit timestamps. A signed 64-bit integer can represent dates up to approximately 292 billion years in the future, effectively eliminating the overflow concern. Most modern Linux kernels, macOS, and Windows versions already use 64-bit time internally. However, legacy embedded systems, older databases, and some file formats may still be vulnerable.