Why Unix Timestamps Exist
Time is deceptively complex in software. Daylight saving shifts, leap seconds, timezone abbreviation conflicts (CST means Central Standard Time in the US but China Standard Time in Asia), and calendar reform differences make human-readable dates unreliable for computation. Unix time solves this by representing every moment as a single integer — the number of seconds since January 1, 1970, 00:00:00 UTC (the “epoch”).
This single-number representation is timezone-agnostic, locale-independent, and trivially sortable. Two timestamps can be subtracted to find elapsed duration. They compress into 4 or 8 bytes in a database column. And every programming language — from C's time() to JavaScript's Date.now() to Python's time.time() — natively produces and consumes it.
Unix Timestamp Formats Across Languages & APIs
| Language / API | Function | Precision |
|---|---|---|
| JavaScript | Date.now() | Milliseconds |
| Python | time.time() | Seconds (float) |
| Java / Kotlin | System.currentTimeMillis() | Milliseconds |
| Go | time.Now().Unix() | Seconds |
| PHP | time() | Seconds |
| MySQL / PostgreSQL | UNIX_TIMESTAMP() / EXTRACT(EPOCH) | Seconds |
| Stripe / Twilio APIs | created_at, date_created | Seconds |
Key takeaway: JavaScript and Java return milliseconds by default, while most backend languages and APIs use seconds. Mixing them up is one of the most common Unix timestamp bugs — a value of 1709510400000 in seconds would place you in the year 56,189.
Seconds vs Milliseconds: Avoiding the #1 Timestamp Bug
Seconds (10 digits)
1709510400
- Standard Unix/POSIX convention
- Used by: C, Go, PHP, Ruby, Stripe, AWS
- Range: 1970 – 2038 (32-bit) or billions of years (64-bit)
- Database storage: 4 bytes (INT) or 8 bytes (BIGINT)
Milliseconds (13 digits)
1709510400000
- Sub-second precision for high-frequency events
- Used by: JavaScript, Java, Kafka, Elasticsearch
- Required for: animation timers, latency measurement
- Database storage: 8 bytes (BIGINT)
Where Unix Timestamps Are Used in Production
JWT Token Expiration
JSON Web Tokens store 'iat' (issued at) and 'exp' (expires at) claims as Unix timestamps in seconds. Incorrect conversion silently creates tokens that never expire or expire instantly.
Database created_at / updated_at
Storing timestamps as integers in PostgreSQL, MySQL, or DynamoDB enables fast range queries, timezone-free comparisons, and efficient indexing without datetime parsing overhead.
Cron Jobs & Schedulers
Task schedulers like Celery, Sidekiq, and AWS EventBridge use Unix timestamps to schedule future execution. Converting human-readable times to Unix time ensures timezone-safe scheduling.
Log Aggregation & SIEM
Centralized logging platforms (ELK Stack, Splunk, Datadog) normalize event timestamps to Unix milliseconds for cross-service correlation and chronological ordering.
Cache TTL & Expiration
Redis EXPIREAT and Memcached use Unix timestamps to set key expiration. Passing milliseconds when seconds are expected multiplies the TTL by 1,000 — keeping stale data for years.
Git Commit Timestamps
Every Git commit stores author and committer timestamps as Unix seconds with timezone offset. Tools like 'git log --format=%at' output raw epoch values for scripting and analysis.
Want to go deeper?
Read our complete guide on Unix timestamps, epoch time conversions, and the Y2K38 problem — covering best practices for handling time across languages and APIs.