Unix Timestamps: Epoch Time Complete Guide
Understand Unix timestamps, epoch time, timezone conversion, and how to work with dates in APIs and databases.
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 supportThe 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 moreTimezone 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