Unix Timestamps & Epoch Time: The Definitive Systems Reference Manual
Complete systems guide to Unix epoch time. Master unit scales (seconds to nanoseconds), cross-language parsing cheatsheets, ISO 8601 conversions, timezone normalization, and browser high-resolution timers.
In distributed architectures, transmitting human-formatted strings like "09/05/2026 10:30 PM" across services introduces parsing overhead, locale ambiguity, and timezone drift. Unix timestamps eliminate this fragility by representing any discrete point in human history as a single, monotonically increasing numerical count of elapsed time.
The Unix Epoch Core Concept and UTC Invariance
The Unix timestamp is defined as the elapsed time since January 1, 1970 at 00:00:00 UTC (the Unix Epoch), discounting leap seconds.
A critical architectural rule: Unix timestamps are strictly timezone-independent. An epoch integer of 1700000000 represents the exact same physical instant whether recorded by an IoT sensor in Tokyo, a server cluster in Frankfurt, or a mobile client in San Francisco. Timezone offsets are purely a presentation-layer concern.
The Precision Spectrum Seconds to Nanoseconds
APIs and storage engines utilize different unit granularities depending on their precision requirements and runtime environments:
| Scale | Digit Count | Multiplier from Seconds | Common Frameworks & Protocols |
|---|---|---|---|
| Seconds | 10 digits (e.g. 1700000000) | 1 | POSIX C APIs, Python time.time(), Redis TTLs, JWT exp |
| Milliseconds | 13 digits (e.g. 1700000000000) | 1,000 (10^3) | JavaScript Date.now(), Java System.currentTimeMillis(), MongoDB |
| Microseconds (µs) | 16 digits (e.g. 1700000000000000) | 1,000,000 (10^6) | PostgreSQL TIMESTAMP, Python datetime.microsecond, Cassandra |
| Nanoseconds (ns) | 19 digits (e.g. 1700000000000000000) | 1,000,000,000 (10^9) | Go time.Now().UnixNano(), Rust SystemTime, Linux tracepoints |
Passing a 10-digit second timestamp to a system expecting 13-digit milliseconds (like JavaScript's Date) interprets the time as occurring a few weeks after January 1, 1970. Always check integer length before parsing.
The JavaScript Nanosecond Overflow BigInt vs MAX SAFE INTEGER
When ingesting high-precision telemetry, OpenTelemetry trace spans, or Go/Rust microservices sending 19-digit nanosecond timestamps (e.g. 1772670600123456789), standard JavaScript number parsing silently loses data:
| Metric / Representation | Value | Data Type | Status / Precision Note |
|---|---|---|---|
| Nanosecond String Input | "1772670600123456789" | String (19 digits) | Exact incoming timestamp |
| Number.MAX_SAFE_INTEGER | 9007199254740991 | 64-bit float limit (16 digits) | Threshold beyond which integer precision corrupts |
| Number(rawString) | 1772670600123456800 | IEEE 754 Float64 | Corrupted: Lower nanosecond digits rounded |
| BigInt(rawString) | 1772670600123456789n | BigInt | 100% exact lossless integer representation |
// Lossy conversion: standard JSON.parse() or Number() corrupts nanoseconds
const rawNanos = "1772670600123456789";
console.log(Number(rawNanos)); // 1772670600123456800 (Lost last 3 digits!)
// Lossless conversion using BigInt
const nanosBigInt = BigInt(rawNanos);
const epochMs = Number(nanosBigInt / 1000000n); // Convert safely to millisecond Date
const date = new Date(epochMs);
console.log(date.toISOString()); // "2026-03-05T00:30:00.123Z"Format Comparison Unix Epoch vs ISO 8601 vs RFC 2822
Selecting the right timestamp serialization format depends on whether your priority is storage density, human inspectability, or HTTP standards compliance:
| Format Standard | Example Serialization | Wire / Storage Size | Timezone Context | Best Operational Use Case |
|---|---|---|---|---|
| Unix Epoch (Seconds) | 1772670600 | 4 or 8 bytes (binary) / 10 bytes (text) | Pure UTC (implicit) | Cache TTLs, Redis keys, JWT token expiration (exp) |
| Unix Epoch (Milliseconds) | 1772670600000 | 8 bytes (binary) / 13 bytes (text) | Pure UTC (implicit) | JavaScript runtimes, database write pipelines, WebSockets |
| ISO 8601 / RFC 3339 | 2026-03-05T00:30:00.000Z | 24–27 bytes (text) | Explicit offset or Z | REST API JSON responses, human-readable logging schemas |
| RFC 2822 / HTTP-Date | Thu, 05 Mar 2026 00:30:00 GMT | 29 bytes (text) | Fixed GMT format | HTTP protocol headers (Last-Modified, If-Modified-Since, Expires) |
Cross Language Timestamp Cheatsheet
Standard patterns for generating current timestamps and parsing epoch values across production languages:
// JavaScript / TypeScript (Node.js & Browser)
const nowSeconds = Math.floor(Date.now() / 1000); // Current epoch (seconds)
const nowMs = Date.now(); // Current epoch (milliseconds)
// Parsing 10-digit epoch to ISO string
const isoString = new Date(nowSeconds * 1000).toISOString();# Python 3.11+
import time
from datetime import datetime, timezone
now_seconds = int(time.time())
utc_dt = datetime.fromtimestamp(now_seconds, tz=timezone.utc)
formatted_iso = utc_dt.isoformat()// Go
package main
import (
"fmt"
"time"
)
func main() {
nowSec := time.Now().Unix() // Seconds (int64)
nowNano := time.Now().UnixNano() // Nanoseconds (int64)
// Parse epoch seconds to UTC time.Time
parsedTime := time.Unix(nowSec, 0).UTC()
fmt.Println(parsedTime.Format(time.RFC3339))
}// Rust
use std::time::{SystemTime, UNIX_EPOCH};
fn main() {
let duration = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
let seconds = duration.as_secs();
let millis = duration.as_millis();
println!("Epoch sec: {}, ms: {}", seconds, millis);
}The Timezone Fallacy Timestamps Have No Timezone
A frequent misconception among developers is asking 'How do I convert a Unix timestamp to UTC?' A Unix timestamp is already in UTC by definition.
What developers actually want is formatting the timestamp into a localized calendar string. To render a timestamp accurately in a user's target timezone, pass the IANA timezone identifier (e.g. America/Los_Angeles, Europe/London, Asia/Tokyo) to your formatter rather than manually adding hour offsets, which breaks during Daylight Saving Time (DST) transitions.
Browser Precision performance now vs Date now
While Date.now() tracks wall-clock Unix epoch time in milliseconds, it is subject to system clock adjustments (NTP synchronizations or manual OS clock edits). For benchmarking sub-millisecond durations, browsers provide performance.now():
| API | Reference Benchmark | Resolution | Susceptible to System Clock Adjustments? |
|---|---|---|---|
| Date.now() | Unix Epoch (1970-01-01T00:00:00Z) | 1 millisecond | Yes (clock can jump forward or backward) |
| performance.now() | Document navigation start (timeOrigin) | 5 to 100 microseconds (mitigated against Spectre) | No (strictly monotonic) |
To learn how the 1970 baseline was established and how 64-bit systems handle Year 2038 boundaries, see our detailed guide on Unix Epoch Time Explained, or practice cross-platform conversions in How to Convert Unix Timestamp.
[NEED: real detail on CoShareX Timestamp Converter features — e.g. relative time calculations ('X hours ago'), human date to epoch interactive picker, batch parsing options, or local timezone auto-detection].
Code Formatter & Converter Suite
Validate, format, minify, and convert JSON, SQL, YAML, XML, and code dialects directly on your local machine.
Frequently Asked Questions
Are Unix timestamps affected by Daylight Saving Time (DST)?
No. Unix timestamps count continuous SI seconds from the 1970 epoch regardless of geographic seasons. DST is an artificial clock shift applied purely by local calendar systems during string rendering.
How can I tell if an unknown timestamp is in seconds or milliseconds?
Inspect the number of digits. If it contains 10 digits (e.g. 1718000000), it is in seconds (valid for years 2001 to 2286). If it contains 13 digits (e.g. 1718000000000), it is in milliseconds.
Does a Unix timestamp include leap seconds?
No. POSIX standard Unix time assumes every day has exactly 86,400 seconds. When leap seconds occur, the clock is adjusted (stepped or smeared) to keep epoch time aligned with solar time.
Conclusion
Standardizing on raw UTC Unix epoch timestamps across backend APIs, distributed queues, and databases decouples your systems from timezone complexities and formatting ambiguities.
Related Articles
How to Convert Unix Timestamps: JavaScript, Python, SQL, and CLI Recipes
Practical developer recipes for bidirectionally converting 10-digit (seconds) and 13-digit (milliseconds) Unix epoch timestamps into UTC, ISO 8601, and local dates across JavaScript, Python, SQL, and terminal CLI tools.
UtilitiesUnix Epoch Time Explained: The 1970 Genesis, Bitwise Y2K38 Overflow, and Leap Second Smearing
Technical systems analysis of Unix epoch time. Learn why January 1, 1970 was chosen, examine the bitwise signed 32-bit integer overflow of the Year 2038 bug, and discover how modern 64-bit systems and NTP leap smearing solve time measurement.