๐ Unix Timestamps: One Number to Rule All Time
Everything you need to know about timestamps โ from the basics to real-world use cases
What Is a Unix Timestamp?
A Unix timestamp is simply the number of seconds that have elapsed since January 1, 1970, 00:00:00 UTC. That date is called the "Unix Epoch" โ the beginning of time as far as computers are concerned.
For example, the timestamp 1717766400 translates to June 8, 2024. Every computer on the planet, regardless of timezone or language, interprets that number as the exact same moment.
Why Developers Use Timestamps
1. No Ambiguity
If you say "3 PM on June 8th," someone in Texas and someone in Tokyo see two different moments. But 1717858800 is the same instant everywhere. Store timestamps in your database instead of formatted dates, and you'll never face the "Beijing time stored, UTC time read" disaster.
2. Plain Numbers, Naturally Sortable
A timestamp is just an incrementing integer. WHERE ts > 1717766400 is faster than WHERE date > '2024-06-08' and requires no date format parsing.
3. Cross-Language Standard
Nearly every programming language has built-in timestamp support:
| Language | Get current timestamp (seconds) |
|---|---|
| JavaScript | Math.floor(Date.now() / 1000) |
| Python | import time; time.time() |
| Go | time.Now().Unix() |
| Java | System.currentTimeMillis() / 1000 |
| Shell | date +%s |
| PHP | time() |
Seconds vs Milliseconds: Don't Mix Them Up
This is the #1 rookie mistake. Timestamps come in two common precisions:
- Second precision (10 digits):
1717766400โ the classic Unix standard, common in databases - Millisecond precision (13 digits):
1717766400000โ JavaScript'sDate.now()returns milliseconds by default
Quick check: 10 digits = seconds, 13 digits = milliseconds. If your API doc says "pass a timestamp" without specifying seconds or milliseconds โ it's almost certainly seconds. If you get it wrong, your date will be sometime in 1970 or 2060. You'll notice.
The Year 2038 Problem: Will Timestamps Overflow?
32-bit systems store timestamps in a signed int32, maxing out at 2147483647 โ which is January 19, 2038, 03:14:07 UTC. After that, the integer overflows into negative territory, wrapping time back to 1901. This is the famous Year 2038 Problem (Y2K38).
Real-world impact? Any device made after ~2010 runs a 64-bit OS, where the timestamp can reach the heat death of the universe. But embedded systems, old routers, and industrial controllers still on 32-bit โ circle January 19, 2038 on your calendar.
Real-World Use Cases
- ๐ Reading logs: Server logs are full of timestamps. When exactly was
1780906800? - ๐ Data analysis: Your CSV has an "order_created" column that's just long numbers. You need batch conversion to dates.
- ๐ฅ Cross-border teams: Your colleague is in San Francisco, you're in Beijing. The database stores one timestamp โ you each need to see your local time.
- ๐ URL parameters: Many sites embed timestamps in shared links for cache-busting.
- ๐งช API debugging: Stripe, AWS, Alibaba Cloud โ all use timestamps for request signing. One wrong digit and the entire request is rejected.
Timezones: The Bridge Between Timestamps and Local Time
A timestamp itself has no timezone โ it's just UTC seconds. But humans need timezones. The same timestamp 1717766400:
- In UTC: 2024-06-08 00:00:00
- In Beijing (UTC+8): 2024-06-08 08:00:00
- In New York (UTC-4): 2024-06-07 20:00:00
This is why an online converter needs timezone support. You found a timestamp in an S3 access log, but you're in Beijing and want to know when it happened in your time โ select UTC+8 and see the result in one click.
Pro tip: Always store timestamps (or UTC) in your database. Format to local time only at the presentation layer. Never store timezone-formatted strings in your database โ that's called "digging your own grave."
๐ Try the converter now
Seconds/milliseconds toggle, 18 timezones, ISO 8601, one-click copy
๐ Open Timestamp ConverterFAQ
Q: Why January 1, 1970?
Unix was designed in the early 1970s, so January 1, 1970 was a convenient round-number starting point with no historical baggage. Some also say it was the birthday of a Unix developer's wife โ but that's apocryphal.
Q: What does a negative timestamp mean?
-1 represents December 31, 1969, 23:59:59 UTC โ a moment before the Unix Epoch. So timestamps can represent dates before 1970; 1950 would be a large negative number.
Q: Is second precision enough?
For 99% of applications โ post times, logs, order creation โ one-second precision is plenty. For high-frequency trading or performance profiling, use millisecond or nanosecond precision. JavaScript's performance.now() offers microsecond resolution.