Unix Timestamp Explained — A Complete Guide to Epoch Time

Open any API response, database row, or log file and you will eventually run into a number like 1752451200. That is a unix timestamp — the backbone of how computers record time. This guide explains what epoch time actually is, why it was designed this way, the seconds-versus-milliseconds split that causes so many bugs, and how to convert timestamps to readable dates in JavaScript, Python, and SQL.

What Is a Unix Timestamp?

A unix timestamp is simply a count of seconds elapsed since 00:00:00 UTC on 1 January 1970. That starting moment is called the unix epoch. The value 0 means the epoch itself; 86,400 means exactly one day later; 1752451200 means 14 July 2025 at midnight UTC.

Why 1970? The unix operating system was developed at Bell Labs around 1969–1971, and its engineers needed a convenient, recent, round starting date for the system clock. 1 January 1970 was chosen, and because unix went on to influence practically every operating system and programming language that followed, the choice stuck. Today epoch time is used by Linux, macOS, Android, databases, JavaScript, Python, Go, and almost every API you will ever call.

The crucial detail is that the count is anchored to UTC. A unix timestamp carries no timezone. Whether your server runs in Mumbai, Frankfurt, or Virginia, the same instant in time produces exactly the same integer.

Why Epoch Time Exists — Timezone-Free Arithmetic

Human date formats are terrible for computation. Is "03/04/2025" the 3rd of April or the 4th of March? How many days are between 28 February and 1 March — it depends on leap years. What time is "9:00 AM" — it depends on where you are standing. Epoch time removes all of that ambiguity by reducing time to a plain integer:

  • Comparison is trivial — a bigger number is always a later moment, so sorting events is just numeric sorting.
  • Duration is subtractionend - start gives elapsed seconds with no calendar logic at all.
  • Storage is compact — one integer instead of a formatted string, which also indexes efficiently in databases.
  • It is timezone-proof — servers in different regions agree on the value without any conversion.
// How long did the job take? No calendars, no timezones.
const start = 1752451200;   // job started
const end   = 1752454800;   // job finished
const durationSeconds = end - start;      // 3600
const durationMinutes = durationSeconds / 60;  // 60 minutes

Seconds vs Milliseconds — Know Your Ecosystem

The single most common timestamp bug is mixing up units. The classic unix timestamp is in seconds, but several major ecosystems count in milliseconds:

Ecosystem / API              Unit          Example (same instant)
---------------------------  ------------  ----------------------
Linux time(), date +%s       seconds       1752451200
Python time.time()           seconds*      1752451200.123 (float)
MySQL UNIX_TIMESTAMP()       seconds       1752451200
JWT exp / iat claims         seconds       1752451200
JavaScript Date.now()        MILLIseconds  1752451200000
Java System.currentTimeMillis MILLIseconds 1752451200000
MongoDB Date type            MILLIseconds  1752451200000

* Python returns seconds as a float with sub-second precision.

A quick heuristic: current timestamps in seconds have 10 digits, while millisecond timestamps have 13 digits. If you feed a seconds value into JavaScript's new Date() without multiplying by 1000, you will get a date in January 1970 — a bug so common we wrote a separate article about it.

Negative Timestamps and Leap Seconds

Two edge cases worth knowing about:

  • Negative timestamps represent moments before 1970. For example, -86400 is 31 December 1969, and India's independence day, 15 August 1947, is roughly -706320000. Most modern languages handle negatives correctly, but some older APIs, JSON parsers, and 32-bit systems do not — test before relying on them for birthdates or historical data.
  • Leap seconds are ignored. Astronomical time occasionally drifts from atomic time, so a leap second is inserted into UTC every few years. Unix time pretends these do not exist: every day is exactly 86,400 seconds. During a leap second the unix clock effectively repeats or smears a second. For 99.9% of applications this is irrelevant, but it means unix time is not a perfect count of physical seconds since 1970 — it is off by 27 seconds and counting.

Converting Timestamps in JavaScript, Python, and SQL

JavaScript — remember: milliseconds.

// Current timestamp
Date.now();                          // 1752451200000 (ms)
Math.floor(Date.now() / 1000);       // 1752451200 (unix seconds)

// Unix seconds -> readable date
const ts = 1752451200;
new Date(ts * 1000).toISOString();   // "2025-07-14T00:00:00.000Z"

// Date -> unix seconds
Math.floor(new Date('2025-07-14T00:00:00Z').getTime() / 1000);

Python — seconds, as a float.

import time
from datetime import datetime, timezone

time.time()                          # 1752451200.123 (seconds, float)

# Unix seconds -> aware datetime in UTC
dt = datetime.fromtimestamp(1752451200, tz=timezone.utc)
print(dt.isoformat())                # 2025-07-14T00:00:00+00:00

# datetime -> unix seconds
int(dt.timestamp())                  # 1752451200

SQL — MySQL and PostgreSQL differ.

-- MySQL
SELECT FROM_UNIXTIME(1752451200);            -- timestamp -> datetime
SELECT UNIX_TIMESTAMP('2025-07-14 00:00:00'); -- datetime -> timestamp

-- PostgreSQL
SELECT to_timestamp(1752451200);              -- timestamp -> timestamptz
SELECT extract(epoch FROM now())::bigint;     -- datetime -> timestamp

For a deeper cookbook with the timezone gotchas of each function, see our timestamp conversion guide.

Frequently Asked Questions

What is a unix timestamp?

It is the number of seconds that have elapsed since 00:00:00 UTC on 1 January 1970, known as the unix epoch. It is a single integer that identifies a moment in time without any timezone information.

Is a unix timestamp in seconds or milliseconds?

The classic unix timestamp is in seconds. However, JavaScript (Date.now()), Java (System.currentTimeMillis()), and many APIs use milliseconds. A 10-digit value is usually seconds and a 13-digit value is usually milliseconds.

Do unix timestamps depend on timezones?

No. A unix timestamp always counts from the epoch in UTC, so the same instant produces the same timestamp everywhere in the world. Timezones only matter when you convert the timestamp into a human-readable date for display.

Try the Free Timestamp Converter

Convert unix timestamps to human-readable dates and back, in your browser. Handles seconds and milliseconds automatically. No signup, no cost.

Related articles