Unix Timestamp Explained: Convert Epoch Time to Readable Date

A Unix timestamp is seconds since 1970-01-01 00:00:00 UTC. Learn conversions, milliseconds vs seconds, negative timestamps, and common mistakes.

Unix Timestamp is a time format that stores the number of seconds since 1970-01-01 00:00:00 UTC (the Unix epoch). It is widely used for logs, APIs, and database fields because it is compact and easy to compare.

Quick Answer

  • 0 = 1970-01-01 00:00:00 UTC
  • 1700000000 = 2023-11-14 22:13:20 UTC
  • 10 digits usually means seconds; 13 digits usually means milliseconds.
  • Store as UTC; convert to local time only for display.

Key Takeaways

  • A Unix timestamp is an integer time value, which makes sorting and math straightforward.
  • The same value displays differently by time zone, but the underlying moment is identical.
  • Most conversion bugs are caused by seconds vs milliseconds or UTC vs local time confusion.
  • Unix timestamps are good for machine workflows; ISO 8601 is often better for human-facing text.

How Unix Time Works

Unix time starts at this fixed reference:

1970-01-01 00:00:00 UTC

Every second after that increases the timestamp by 1.

  • 1 = one second after the epoch
  • 86400 = one day after the epoch
  • -1 = one second before the epoch

Why Developers Use It

Property Unix Timestamp
Format Integer
Time zone basis UTC
Arithmetic Easy (add/subtract seconds)
Storage size Compact
Human readability Low without conversion

Timestamp to Date Conversion

To convert a Unix timestamp to a readable date:

  1. Confirm units: seconds or milliseconds.
  2. Parse as UTC epoch time.
  3. Format in the required time zone.

Example using seconds:

1700000000 seconds after 1970-01-01 00:00:00 UTC
-> 2023-11-14 22:13:20 UTC

Date to Timestamp Conversion

To convert a date to Unix time:

  1. Normalize the date/time to UTC.
  2. Calculate seconds from the Unix epoch.
  3. Use milliseconds only if your system expects them.
Timestamp (seconds) = UTC instant - epoch in seconds
Timestamp (milliseconds) = seconds * 1000

Worked Examples

Input Output Note
0 1970-01-01 00:00:00 UTC Epoch start
946684800 2000-01-01 00:00:00 UTC Y2K moment
1700000000 2023-11-14 22:13:20 UTC Common test value
1700000000000 2023-11-14 22:13:20 UTC Milliseconds version
-1 1969-12-31 23:59:59 UTC Pre-epoch time

Programming Examples

Use UTC-aware methods to avoid silent time zone shifts.

JavaScript

// Current Unix time in seconds
Math.floor(Date.now() / 1000);

// Seconds -> Date (UTC instant)
new Date(1700000000 * 1000);

// Date string -> Unix seconds
Math.floor(new Date("2023-11-14T22:13:20Z").getTime() / 1000);

JavaScript Date stores milliseconds internally.

Python

import time
from datetime import datetime, timezone

# Current Unix timestamp (seconds)
time.time()

# Seconds -> UTC datetime
datetime.fromtimestamp(1700000000, tz=timezone.utc)

# UTC datetime -> timestamp
datetime(2023, 11, 14, 22, 13, 20, tzinfo=timezone.utc).timestamp()

PHP

// Current Unix timestamp (seconds)
time();

// Seconds -> UTC date string
gmdate('Y-m-d H:i:s', 1700000000);

// UTC date-time -> timestamp
strtotime('2023-11-14 22:13:20 UTC');

Common Mistakes

1. Mixing Seconds and Milliseconds

If your result lands in year 55840 or 1970 unexpectedly, units are likely wrong.

  • Seconds: 1700000000 (10 digits)
  • Milliseconds: 1700000000000 (13 digits)

2. Treating Local Time as UTC

A local date parsed without explicit zone can shift the output timestamp.

3. Assuming All Systems Use the Same Unit

Many databases, analytics platforms, and APIs document unit conventions differently.

4. Displaying Raw Timestamps to End Users

Raw epoch values are machine-oriented. Convert before rendering UI text.

Year 2038 Boundary

If a system stores timestamp seconds as signed 32-bit integers, max value is 2147483647, which corresponds to:

2038-01-19 03:14:07 UTC

After this point, 32-bit signed storage overflows. Most current platforms use 64-bit storage, but embedded/legacy systems can still be affected.

When Unix Timestamp Is Useful (and Not)

Scenario Fit
API request/response fields Strong
Log event ordering Strong
Date arithmetic in code Strong
Human-readable legal/audit text Limited
User-facing dates without conversion Poor

FAQ

What is epoch time vs Unix timestamp?

In most software discussions they mean the same thing: elapsed time since 1970-01-01 00:00:00 UTC.

Is Unix timestamp always UTC?

Yes. The stored value is UTC-based. Time zone only affects display formatting.

Why is my converted date different across devices?

Different local time zones and locale formatting settings can show different local strings for the same UTC instant.

How do I know if a timestamp is milliseconds?

Check digits and docs. Around current years, seconds are near 10 digits and milliseconds near 13 digits.

Can I use Unix timestamps before 1970?

Yes, with negative values, if your language and database support them correctly.

Should I use Unix timestamp in databases?

It is common for event tables and ordering. If human-readable storage is important, ISO 8601 strings are often easier to inspect.

Is leap second handling included?

Unix time typically ignores leap seconds in everyday app logic, so it behaves as continuous SI-second counting in common runtime APIs.

What is the easiest way to convert quickly?

Use a dedicated converter and keep unit selection explicit (seconds vs milliseconds).

Convert Timestamps

Unix Timestamp Converter

Convert Unix timestamps to dates and back with explicit seconds/milliseconds handling.

Open Converter

Related Tools

Related Tools