Unix Timestamps: Epoch Time Complete Guide

Understand Unix timestamps, epoch time, timezone conversion, and how to work with dates in APIs and databases.

5 min read Time · APIs · Databases 6 sections + FAQ

A Unix timestamp is the number of seconds (or milliseconds) elapsed since January 1, 1970, 00:00:00 UTC. It is the universal way to represent a moment in time that works identically in every timezone, on every operating system, in every programming language.

Timestamps eliminate timezone ambiguity from data storage. When a server stores 1704067200 instead of "January 1, 2024 at midnight", there is no ambiguity — it is the same moment regardless of where the server or user is located.

What is a Unix timestamp

A Unix timestamp (also called a POSIX timestamp or epoch timestamp) counts seconds since the Unix epoch. It is a single integer — positive for dates after 1970, negative for dates before. The current timestamp grows by exactly 1 every second. Because it is a simple number with no timezone information embedded, the same timestamp always refers to the same moment in time anywhere on Earth.

Free Tool Timestamp Converter Convert Unix timestamps to dates and back, with timezone support

The Unix epoch (January 1, 1970)

The epoch — January 1, 1970, 00:00:00 UTC — was chosen by Unix engineers as a convenient starting point. It has no special significance in astronomy or mathematics. The choice means that timestamps from before 1970 are negative (though most systems use unsigned integers and simply do not support pre-1970 dates). The epoch date was selected in the early 1970s when Unix was being developed at Bell Labs.

Milliseconds vs seconds

Original Unix timestamps count seconds. JavaScript's Date.now() returns milliseconds (multiply by 1000). Many APIs — including Stripe, Twilio, and most modern REST APIs — use seconds. Some APIs like Slack and Discord use milliseconds. Always check the API documentation. A timestamp of 1704067200 is in seconds (2024-01-01). A timestamp of 1704067200000 is in milliseconds (also 2024-01-01). If a date appears to be in 2525, you are probably treating milliseconds as seconds.

Free Tool Unit Converter Convert length, mass, temperature, area, volume and more

Timezone considerations

Unix timestamps are inherently UTC — they measure seconds since the UTC epoch. Timezones only come into play when displaying the timestamp as a human-readable date. January 1, 2024, 00:00:00 UTC is timestamp 1704067200. That same moment is December 31, 2023, 19:00:00 in New York (UTC-5). The timestamp is identical; only the human representation changes. Always store timestamps as UTC. Convert to local time only in the presentation layer.

Timestamps in APIs and databases

APIs typically return timestamps in one of four formats: Unix timestamp in seconds (integer), Unix timestamp in milliseconds (integer), ISO 8601 string ("2024-01-01T00:00:00Z"), or RFC 2822 string (used in email headers). Databases offer dedicated timestamp types: PostgreSQL has TIMESTAMP WITH TIME ZONE, MySQL has DATETIME and TIMESTAMP, SQLite stores timestamps as TEXT or INTEGER. Use INTEGER (Unix timestamp) for maximum portability across systems.

Converting to human-readable dates

In JavaScript: new Date(timestamp * 1000).toISOString() converts a seconds timestamp to ISO 8601. In Python: datetime.utcfromtimestamp(timestamp) converts to a datetime object. In SQL: FROM_UNIXTIME(timestamp) in MySQL, to_timestamp(timestamp) in PostgreSQL. Online converters like the PixCode Timestamp Converter handle the math instantly and show the result in multiple formats and timezones.

Free Tool JSON Formatter & Validator Format, validate and minify JSON data with syntax highlighting

Frequently Asked Questions

What is the Unix epoch? +
The Unix epoch is January 1, 1970, 00:00:00 UTC — the reference point from which all Unix timestamps are counted. It was chosen by Unix developers in the early 1970s as a convenient starting date.
What is the current Unix timestamp? +
Unix timestamps grow by 1 every second. You can get the current timestamp in JavaScript with Math.floor(Date.now() / 1000), in Python with int(time.time()), and in most shells with date +%s.
What is the Year 2038 problem? +
Systems that store Unix timestamps as 32-bit signed integers will overflow on January 19, 2038, at 03:14:07 UTC. This is the Unix equivalent of the Y2K bug. The fix is to use 64-bit integers, which can store timestamps for billions of years.
Are Unix timestamps affected by leap seconds? +
Officially no — Unix time ignores leap seconds. A day always has exactly 86400 seconds in Unix time, even on days with leap seconds. In practice, systems use NTP smearing to absorb leap seconds gradually.
What is the difference between UTC and GMT? +
For practical purposes, UTC and GMT are identical. GMT is a timezone; UTC is an international time standard. Both refer to the same time. Unix timestamps are always UTC.
How do I convert a timestamp to a specific timezone? +
Convert the UTC timestamp to a Date object first, then format it in the target timezone. In JavaScript: new Intl.DateTimeFormat("en-US", { timeZone: "America/New_York" }).format(new Date(ts * 1000)).
What is an ISO 8601 date string? +
ISO 8601 is an international date format standard: 2024-01-01T00:00:00Z. The Z suffix means UTC. Offsets like +05:30 specify a timezone offset. ISO 8601 is unambiguous and widely supported.