正在加载,请稍候…

Unix Timestamp Guide: What It Is, How to Convert, and Why It Matters

Understand Unix timestamps, convert between timestamps and human-readable dates, and learn about timezone pitfalls.

What Is a Unix Timestamp?

A Unix timestamp (also called POSIX time or epoch time) is the number of seconds that have elapsed since January 1, 1970, 00:00:00 UTC - the "Unix epoch." It is a simple, universal, and timezone-independent way to represent a specific point in time.

Current time (example):  2025-06-15 14:30:00 UTC
Unix timestamp:          1750000200

The Unix timestamp is an integer - no timezone, no locale, no calendar system. It is the same number everywhere in the world at any given moment.

Why Unix Time?

Unix timestamps offer several advantages. They are timezone-agnostic: the timestamp does not change depending on where you are, and converting to local time is purely a display concern. They enable simple arithmetic: comparing times, calculating durations, and sorting records are all just integer operations. They have universal support: every programming language, database, and operating system understands Unix timestamps. And they are compact for storage: a 32-bit integer (or 64-bit for post-2038 dates) stores any date/time efficiently.

The Year 2038 Problem

32-bit signed integers can store values up to 2,147,483,647, which corresponds to January 19, 2038, 03:14:07 UTC. After this moment, 32-bit timestamps overflow to negative values, causing incorrect dates on systems that have not migrated to 64-bit. Modern 64-bit timestamps extend the range to approximately the year 292 billion - safely beyond any practical concern.

Unix Time vs. Human-Readable Time

Format Example Timezone
Unix timestamp 1750000200 Always UTC
ISO 8601 2025-06-15T14:30:00Z UTC specified
RFC 2822 Mon, 15 Jun 2025 14:30:00 +0000 Specified
Local time Jun 15, 2025 10:30 AM EDT Local

Working with Unix Timestamps in Code

// JavaScript
const now = Date.now();                    // Milliseconds since epoch
const nowSeconds = Math.floor(Date.now() / 1000); // Seconds

// Convert timestamp to Date
const date = new Date(1750000200 * 1000); // Multiply by 1000 (ms)
console.log(date.toISOString());           // "2025-06-15T14:30:00.000Z"

// Convert Date to timestamp
const timestamp = Math.floor(new Date('2025-06-15T14:30:00Z').getTime() / 1000);
# Python
import time
from datetime import datetime, timezone

now = int(time.time())  # Current timestamp

# Timestamp to datetime
dt = datetime.fromtimestamp(1750000200, tz=timezone.utc)

# Datetime to timestamp
timestamp = int(datetime(2025, 6, 15, 14, 30, tzinfo=timezone.utc).timestamp())
-- SQL (PostgreSQL)
SELECT EXTRACT(EPOCH FROM NOW())::INTEGER;     -- Current timestamp
SELECT TO_TIMESTAMP(1750000200);               -- Timestamp to datetime

Unix Timestamps in Logs and APIs

Many systems use Unix timestamps for event logging and API responses:

  • JWT exp claim: { "exp": 1750000200 }
  • AWS API responses: { "LastModified": 1750000200 }
  • Database columns: created_at INTEGER DEFAULT (unixepoch())

Milliseconds vs. Seconds

Different systems use different resolutions. JavaScript Date.now() returns milliseconds, while Python time.time() returns seconds. A common bug is using milliseconds where seconds are expected, producing dates in 1970 or far in the future.

How to Use This Tool

Enter a Unix timestamp (seconds or milliseconds) to see the corresponding UTC and local date/time, or enter a date and time to get the Unix timestamp. Click "Now" to get the current timestamp instantly.

-> Try the Unix Timestamp Converter