Unix Timestamp & Epoch Time: The Complete Developer Guide
Unix time (also known as Epoch time or POSIX time) is a system for describing a point in time. It is defined as the number of seconds that have elapsed since the Unix Epoch:
January 1, 1970 at 00:00:00 UTC (excluding leap seconds).
In this guide, we'll cover key timestamp operations, unit differences, and timezone parsing.
Seconds vs. Milliseconds
One of the most common developer mistakes is mixing up seconds and milliseconds:
- Seconds (10 digits): Standard Unix timestamps (e.g.
1770000000). Used by languages like PHP, Python, and Go's basic APIs. - Milliseconds (13 digits): Used in JavaScript (
Date.now()) and Java (System.currentTimeMillis()) to provide sub-second precision (e.g.1770000000000).
To convert:
- Seconds to Milliseconds: Multiply by 1000.
- Milliseconds to Seconds: Divide by 1000 and round down (
Math.floor).
Unix Timestamp Converter
Convert Unix timestamps to human dates and parse date strings into epoch seconds or milliseconds online with automatic local and UTC timezone detection.
Parsing Timestamps in Code
Here is how you can parse or generate Unix Epoch timestamps in popular languages:
JavaScript / TypeScript
// Current Epoch in Seconds
const seconds = Math.floor(Date.now() / 1000);
// Epoch to Human Date
const date = new Date(1770000000 * 1000);
console.log(date.toUTCString());Python
import time
from datetime import datetime
# Current Epoch in Seconds
seconds = int(time.time())
# Epoch to Human Date
date = datetime.utcfromtimestamp(1770000000)
print(date.strftime('%Y-%m-%d %H:%M:%S UTC'))Timezone Pitfalls
Unix time is always UTC. It does not change based on geographic location. When formatting an epoch into a display string, always verify whether you are rendering it in the user's Local timezone or standard UTC.