Unix Timestamps: A Complete Developer Guide
Master Unix epoch time, seconds vs milliseconds, ISO 8601 parsing, timezone math, and how systems solve the upcoming Year 2038 bug.
What Is Unix Time?
Unix time (also known as Epoch time or POSIX time) represents the number of seconds that have elapsed since midnight (00:00:00 UTC) on January 1, 1970, excluding leap seconds. It is the universal temporal coordinate system across modern operating systems, networked protocols, and distributed databases.
Why Unix Timestamps Are Universal
Representing time as a single integer eliminates numerous common programming headaches:
- Timezone Independence: A Unix timestamp represents an absolute instant in time that is identical regardless of whether you are in Tokyo, London, or San Francisco.
- Simple Arithmetic: Calculating elapsed duration between two events requires only integer subtraction:
duration = end_time - start_time. - Lightweight Storage: Storing a 32-bit or 64-bit integer requires substantially less database storage and indexing overhead than textual date formats.
Common Language Examples for Working with Unix Time
JavaScript / TypeScript
// Current timestamp in milliseconds const ms = Date.now(); // Current timestamp in seconds const s = Math.floor(Date.now() / 1000); // Convert timestamp to Date object const date = new Date(1700000000 * 1000); console.log(date.toISOString());Python
import time from datetime import datetime, timezone # Current timestamp in seconds (float) current_epoch = time.time() # Convert epoch to UTC datetime dt = datetime.fromtimestamp(1700000000, tz=timezone.utc) print(dt.isoformat())The Year 2038 Bug (Y2038)
On early Unix machines, time was stored as a 32-bit signed integer (time_t). The maximum value of a 32-bit signed integer is 2,147,483,647, which corresponds to Tuesday, 19 January 2038 at 03:14:07 UTC. At the next second, the integer overflows and rolls over to negative -2,147,483,648, which systems interpret as December 13, 1901.
Modern 64-bit systems represent timestamps using 64-bit integers. A 64-bit timestamp will not overflow for roughly 292 billion years, far beyond the lifespan of our sun.
Frequently Asked Questions About Timestamps
Do Unix timestamps account for leap seconds?
Strictly speaking, standard POSIX Unix time ignores leap seconds. When an official leap second is inserted into UTC by the International Earth Rotation and Reference Systems Service (IERS), Unix clocks typically repeat second 59, step backwards one second, or use "leap smear" (gradually stretching seconds across a 24-hour window, as implemented by Google and AWS NTP servers) to maintain monotonic clock synchronization.
How do I handle daylight saving time (DST) with timestamps?
Because Unix timestamps represent raw elapsed seconds since the 1970 epoch in UTC, they are completely immune to Daylight Saving Time shifts. DST is purely a regional presentation artifact. Always store and process timestamps in UTC integers on your servers, and only convert to localized timezones when rendering the date in the user's UI.
Why does JavaScript use milliseconds instead of seconds?
When Brendan Eich created JavaScript in 1995, he modeled the Date object directly after Java's java.util.Date, which measured time in milliseconds from the epoch. This provides micro-timing precision for performance benchmarking, animations, and high-frequency events.
ISO 8601 Date Formatting Standards
When serializing dates as text across APIs, the international standard ISO 8601 (e.g. 2026-10-14T14:30:00Z) should always be preferred over regional formats like MM/DD/YYYY or DD/MM/YYYY, which cause ambiguous date parsing errors.
Try the related tool
Unix Timestamp ConverterMore guides
- How to Format and Validate JSON
- Base64 Encoding and Decoding Explained
- URL Encoding: A Practical Guide
- How to Compare Two Text Files
- Regular Expressions for Beginners
- What Is a UUID? Versions, Formats and Best Practices
- Hash Functions Explained: SHA-256, SHA-1 and Beyond
- JSON Web Tokens (JWT) Explained
- How to Create Strong Passwords
- HEX, RGB and HSL Colors Explained