时间戳转换 使用教程
详细使用指南、最佳实践与常见问题解答
使用场景
时间戳转换工具适用于后端 API 调试、数据库记录查询、日志分析、跨时区时间计算、定时任务配置等场景。当你需要把 Unix 时间戳转成可读时间,或反向获取当前时间戳时,这个工具能快速完成双向转换。
Use Cases
The timestamp converter is useful for backend API debugging, database record queries, log analysis, cross-timezone time calculations, and cron job configuration. Use it to convert Unix timestamps to readable times or to get the current timestamp.
功能特点
- 实时显示:当前时间戳和当前时间实时更新
- 双向转换:时间戳 ↔ 日期时间
- 秒/毫秒:支持秒级和毫秒级时间戳
- 本地时区:自动按浏览器时区显示
- 一键复制:结果可快速复制
Features
- Real-time display: current timestamp and time update live
- Bidirectional: timestamp ↔ date-time
- Seconds/milliseconds: supports both second and millisecond timestamps
- Local timezone: automatically uses browser timezone
- One-click copy: results can be quickly copied
使用示例
示例 1:场景一:后端 API 返回 `created_at: 1719500000`,粘贴到工具里立即看到对应的可读时间。
示例 2:场景二:数据库日志显示 `2024-06-27 15:30:00`,需要转为时间戳用于计算时间差。
示例 3:场景三:配置 cron 任务,需要知道某个未来时间点的时间戳,输入日期时间即可获取。
Examples
Example 1: Scenario 1: Backend API returns `created_at: 1719500000` — paste it in to instantly see the readable time.
Example 2: Scenario 2: Database logs show `2024-06-27 15:30:00` and you need the timestamp to calculate time differences.
Example 3: Scenario 3: Configure a cron job and need the timestamp for a future point in time — enter the date-time to get it.
最佳实践
- 注意区分秒级和毫秒级时间戳(13 位通常是毫秒)
- 跨时区场景统一使用 UTC 时间戳存储,显示时再转本地时区
- 历史时间戳(1970 年之前)在 JavaScript 中可能不准确
- 2038 年问题:32 位 Unix 时间戳将在 2038 年溢出,建议使用 64 位系统
Best Practices
- Distinguish between second and millisecond timestamps (13 digits usually means milliseconds)
- For cross-timezone scenarios, store UTC timestamps uniformly and convert to local timezone on display
- Historical timestamps (before 1970) may be inaccurate in JavaScript
- Year 2038 problem: 32-bit Unix timestamps will overflow in 2038 — use 64-bit systems
常见问题
时间戳是什么?
Unix 时间戳是从 1970 年 1 月 1 日 00:00:00 UTC 到指定时间的秒数(或毫秒数)。它是跨平台、跨时区的通用时间表示方式。
如何区分秒级和毫秒级时间戳?
通常 10 位数字是秒级时间戳(如 1719500000),13 位数字是毫秒级(如 1719500000000)。JavaScript 的 Date.now() 返回毫秒级。
为什么显示的时间和数据库不一致?
通常是因为时区差异。本工具按浏览器本地时区显示,数据库可能存储 UTC 时间。检查时区设置是否一致。
FAQ
What is a timestamp?
A Unix timestamp is the number of seconds (or milliseconds) elapsed since 1970-01-01 00:00:00 UTC. It is a universal, cross-platform, cross-timezone time representation.
How do I distinguish second vs millisecond timestamps?
Typically 10-digit numbers are second timestamps (e.g., 1719500000), and 13-digit numbers are milliseconds (e.g., 1719500000000). JavaScript's Date.now() returns milliseconds.
Why does the displayed time differ from the database?
Usually due to timezone differences. This tool displays in the browser's local timezone, while the database may store UTC. Check that timezone settings match.