Understanding Unix Timestamps Once and For All

Looking to convert a Unix timestamp to date online or convert a date to Unix timestamp? Unix timestamps are ubiquitous in development: databases, APIs, logs, file systems… Yet they often remain poorly understood, a source of subtle bugs related to time zones.

What does 1735689600 represent? Without a tool, impossible to know. And timezone conversion errors can cause critical problems: shifted events, corrupted data, or worse, erroneous financial transactions.

Our timestamp converter is a free online epoch tool that allows you to instantly convert between timestamps and readable dates. In this article, master Unix timestamps once and for all and avoid common pitfalls.

What is a Unix Timestamp?

A Unix timestamp represents a precise moment in time as a unique number: the number of seconds elapsed since January 1, 1970 at 00:00:00 UTC.

This reference date is called the Unix Epoch or POSIX Epoch.

Concrete Examples

TimestampCorresponding Date
0January 1, 1970 00:00:00 UTC
1000000000September 9, 2001 01:46:40 UTC
1609459200January 1, 2021 00:00:00 UTC
1735689600January 1, 2025 00:00:00 UTC

Test with our timestamp converter!

Why Use Timestamps?

1. Universality

A timestamp is independent of time zone. The timestamp 1609459200 represents the same moment everywhere in the world, whether you’re in Paris, New York or Tokyo.

2. Storage Simplicity

A simple integer is lighter and faster to process than a formatted date string:

// Compact and efficient
1609459200

// Heavier
"2021-01-01T00:00:00.000Z"

3. Simplified Calculations

Temporal operations become simple additions/subtractions:

const now = Math.floor(Date.now() / 1000);
const inThreeDays = now + (3 * 24 * 60 * 60);
const oneHourAgo = now - 3600;

4. Natural Sorting

Timestamps sort naturally in chronological order:

events.sort((a, b) => a.timestamp - b.timestamp);

5. Simple Comparisons

if (expirationTimestamp < Date.now() / 1000) {
  console.log("Token has expired");
}

Seconds vs Milliseconds

The Classic Trap

The difference in precision between seconds and milliseconds is a source of many bugs.

FormatLengthExample Value
Seconds (Unix)10 digits1735689600
Milliseconds (JS)13 digits1735689600000

JavaScript Uses Milliseconds

// Date.now() returns milliseconds
Date.now(); // 1735689600000

// new Date() expects milliseconds
new Date(1735689600000); // ✅ Correct
new Date(1735689600);    // ❌ January 18, 1970!

Conversion Between Formats

// Seconds → Milliseconds
const ms = timestamp * 1000;

// Milliseconds → Seconds
const sec = Math.floor(Date.now() / 1000);

Our timestamp converter automatically detects the input format.

Practical Conversions

JavaScript

// Current timestamp (seconds)
const now = Math.floor(Date.now() / 1000);

// Date → Timestamp
const timestamp = Math.floor(new Date("2025-01-01").getTime() / 1000);

// Timestamp → Date
const date = new Date(timestamp * 1000);

// Readable formatting
date.toISOString();      // "2025-01-01T00:00:00.000Z"
date.toLocaleDateString('en-US'); // "1/1/2025"

Python

import time
from datetime import datetime

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

# Date → Timestamp
dt = datetime(2025, 1, 1)
timestamp = int(dt.timestamp())

# Timestamp → Date
date = datetime.fromtimestamp(timestamp)

# Formatting
date.strftime("%m/%d/%Y %H:%M:%S")  # "01/01/2025 00:00:00"

PHP

// Current timestamp
$now = time();

// Date → Timestamp
$timestamp = strtotime("2025-01-01");

// Timestamp → Date
$date = date("m/d/Y H:i:s", $timestamp);

// With DateTime
$dt = new DateTime("@$timestamp");

SQL

-- MySQL
SELECT UNIX_TIMESTAMP(NOW());
SELECT FROM_UNIXTIME(1735689600);

-- PostgreSQL
SELECT EXTRACT(EPOCH FROM NOW());
SELECT TO_TIMESTAMP(1735689600);

-- SQLite
SELECT strftime('%s', 'now');
SELECT datetime(1735689600, 'unixepoch');

The Year 2038 Problem

The 32-bit System Limit

Signed 32-bit integers can store values up to 2,147,483,647. This maximum will be reached on January 19, 2038 at 03:14:07 UTC.

After this date, on non-updated systems, the timestamp “overflows” and becomes negative, resetting the date to… 1901.

Modern Solutions

SolutionDescription
64-bit integersLimit pushed to 292 billion years
Millisecond timestamps64 bits by default in JavaScript
Modern librariesLuxon, Day.js, date-fns use safe formats

Modern systems (64-bit Linux, 64-bit Windows, macOS) are generally prepared.

Time Zones and Common Pitfalls

The Timestamp is ALWAYS in UTC

This is the most important point to remember. A timestamp has no time zone – it represents an absolute moment.

Pitfall 1: Creating Date Without Timezone

// ⚠️ Interpreted in local browser/server time
new Date("2025-01-01")  // Might give December 31, 2024 23:00 UTC!

// ✅ Explicitly specify UTC
new Date("2025-01-01T00:00:00Z")

Pitfall 2: Comparing Dates Between Timezones

// A user in Paris and one in New York see "01/01/2025"
// But their local timestamps are different!

// ✅ Always store and compare in UTC
const startOfDay = new Date("2025-01-01T00:00:00Z").getTime() / 1000;

Pitfall 3: Daylight Saving Time (DST)

During time changes, some local times don’t exist or exist twice:

// On March 26, 2025, switch to daylight saving time in France
// 02:30 becomes 03:30 → 02:30 doesn't exist!

Solution: Always store and manipulate in UTC. Convert only for display.

Timestamps in APIs

Best Practices

  1. Document the format: Seconds or milliseconds?
  2. Use ISO 8601 for readability: 2025-01-01T12:00:00Z
  3. Support both: Accept timestamps and ISO dates as input
  4. Return UTC: No specific time zone

API Response Example

{
  "created_at": 1735689600,
  "created_at_iso": "2025-01-01T00:00:00Z",
  "timezone": "UTC"
}

Timestamps and Databases

DatabaseRecommended Type
PostgreSQLTIMESTAMPTZ (timestamp with time zone)
MySQLDATETIME or TIMESTAMP
SQLiteINTEGER (Unix timestamp) or TEXT (ISO 8601)
MongoDBDate (stored in milliseconds)

PostgreSQL Example

CREATE TABLE events (
    id SERIAL PRIMARY KEY,
    name VARCHAR(255),
    event_time TIMESTAMPTZ DEFAULT NOW()
);

-- Query by period
SELECT * FROM events
WHERE event_time BETWEEN
    TO_TIMESTAMP(1735689600) AND
    TO_TIMESTAMP(1735776000);

Debugging Timestamps

Recognizing the Format

Number of DigitsProbable Format
10Unix seconds
13JavaScript milliseconds
16Microseconds
19Nanoseconds

Quick Verification

Our timestamp converter:

  • Automatically detects the format
  • Displays the date in multiple time zones
  • Allows conversion in both directions

Complementary Tools

To work efficiently with dates and time:

Conclusion

Unix timestamps are simple in appearance but full of subtleties. The key points to remember:

  1. UTC only: The timestamp has no time zone
  2. Watch for milliseconds: 10 or 13 digits makes all the difference
  3. Convert on display: Store in UTC, display in local
  4. Prepare for 2038: Use 64-bit integers

Need to convert a timestamp quickly? Our timestamp converter is here to help!