What Is a Unix Timestamp and How Do You Use It?
A Unix timestamp, sometimes called epoch time, is the number of seconds that have passed since midnight on 1 January 1970 UTC. It is one of the simplest and most portable ways to represent a moment in time, which is why it appears in APIs, databases and logs everywhere.
Why store time as a number?
Storing time as a plain integer has several practical advantages:
- It is timezone-neutral, so different systems agree on the same instant.
- It is compact and easy to compare or sort.
- It converts cleanly to and from human-readable dates.
The trade-off is that a raw number such as 1728000000 is meaningless to a person until it is converted.
Seconds versus milliseconds
The most common source of bugs is mixing up units. JavaScript works in milliseconds, while many APIs and databases use seconds. A timestamp that looks plausible in one unit is wildly wrong in the other.
As a rule of thumb, a value near 1.7 billion is in seconds for the early 2020s, while a value near 1.7 trillion is the same instant in milliseconds.
Converting in common languages
JavaScript:
const nowSeconds = Math.floor(Date.now() / 1000)
const date = new Date(nowSeconds * 1000)
console.log(date.toISOString())
Python:
from datetime import datetime, timezone
now = int(datetime.now(timezone.utc).timestamp())
print(datetime.fromtimestamp(now, tz=timezone.utc).isoformat())
PHP:
$now = time();
echo date('c', $now);
Common pitfalls
- Always know whether a value is seconds or milliseconds.
- Store UTC, then format to a local timezone only at the display layer.
- Watch for the year 2038 problem in systems that use signed 32-bit seconds.
Frequently asked questions
- Is a Unix timestamp the same in every timezone? Yes. It is an absolute point in time; only the formatted representation changes.
- Can I convert a timestamp without uploading it? Yes. Conversion is simple arithmetic and can run entirely in your browser.
Need to convert timestamps both ways quickly and privately? Try the free Unix Timestamp Converter — it handles seconds and milliseconds and runs locally.