Unix Timestamps: Complete Developer Guide 2025
What Unix timestamps are, why APIs use them, and how to convert between seconds, milliseconds, and human-readable dates.
If you've ever looked at a database and seen a number like 1735689600 instead of a date, you've encountered a Unix timestamp. It's the heartbeat of modern computing, but it can be confusing for beginners.
What is the Unix Epoch?
Unix time is a system for describing a point in time. It is the number of seconds that have elapsed since the Unix Epoch, which is 00:00:00 UTC on 1 January 1970.
Why 1970? It was chosen as a convenient round number by the engineers developing the original Unix operating system at Bell Labs.
The Year 2038 Problem
On 32-bit systems, the timestamp is stored as a signed 32-bit integer. The maximum value this can hold corresponds to January 19, 2038. After this second, the counter will overflow and wrap around to December 13, 1901.
Most modern systems have migrated to 64-bit integers, which pushes the overflow date to approximately 292 billion years in the future safe to say, not our problem!
Handling Timestamps in Code
JavaScript
// Get current timestamp (milliseconds)
const now = Date.now();
// Convert to seconds
const unix = Math.floor(Date.now() / 1000);Python
import time
unix = int(time.time())Seconds vs. Milliseconds
There's an important distinction to understand:
- Unix Timestamp (seconds): The traditional format, counting seconds since epoch. Example:
1735689600 - JavaScript Timestamp (milliseconds): JavaScript's
Date.now()returns milliseconds. Example:1735689600000
This difference causes bugs when mixing systems. Always check whether your system uses seconds or milliseconds!
Common Use Cases
API Responses
Many REST APIs return timestamps as Unix integers. Converting them to readable dates is essential for debugging and displaying to users.
Database Storage
Storing dates as integers is more efficient than strings and allows for easy range queries. You can quickly find all records created in the last 24 hours by comparing timestamps.
Cache Expiration
Setting cache expiration times often requires calculating "current time + X seconds". Unix timestamps make this arithmetic straightforward.
Log Analysis
Log files often contain Unix timestamps. Converting them helps correlate events across different systems and timezones.
Timezone Considerations
Unix timestamps are always in UTC (Coordinated Universal Time). This is crucial because:
- UTC is timezone-independent, making it perfect for distributed systems
- When converting to local time, you must account for timezone offsets
- Daylight Saving Time (DST) changes don't affect Unix timestamps
- Two events happening at the same moment anywhere in the world have the same timestamp
Always store timestamps in UTC and convert to local time only when displaying to users.
Converting Human Dates
Calculating these large numbers in your head is impossible. Whether you're debugging an API response or setting a database expiration, you need a quick way to convert between human-readable dates and Unix seconds.
Our Timestamp Converter handles both seconds and milliseconds, and supports ISO 8601 formats for complete flexibility. It's perfect for:
- Converting API response timestamps to readable dates
- Calculating expiration times for cache or sessions
- Debugging time-related bugs in your applications
- Understanding how different systems represent time
- Converting between timezones and formats
Part of the ThenCatch blog. Learn more about us or browse more guides.