What is 169872... Coming from the Backend? Time-stamp Pitfalls Every Dev & Op Should Know
The Bug That Drives Newbies Crazy
Scene reconstruction:
You developed an order system in China (UTC+8), and a user placed an order at 2023-10-31 10:00:00.
The backend database stores this as a time string.
Your boss, on a business trip in the US (UTC-5), opens the dashboard and exclaims, "Whoa, why is someone placing an order at 1 AM?"
This is a classic disaster caused by not having a unified time zone.
What is a Unix Timestamp?
To solve the problem of inconsistent global time, smart engineers invented the Unix Timestamp:
The total number of seconds that have elapsed since January 1, 1970, 00:00:00 UTC.
Whether you are in Tokyo or New York, the Unix timestamp at this very moment is exactly the same (e.g., 1698724800).
It is an absolute value that does not contain any time zone information.
Common Pitfalls
-
Seconds vs. Milliseconds
- Python/PHP defaults to seconds (10 digits, e.g.,
1698724800). - Java/JavaScript defaults to milliseconds (13 digits, e.g.,
1698724800000). - This 1000x difference is the culprit behind times showing up as "1970" or "the year 50,000."
- Python/PHP defaults to seconds (10 digits, e.g.,
-
Daylight Saving Time (DST)
- If you're still manually adding or subtracting 1 hour to handle time, please stop this dangerous behavior. DST rules can change every year; leave it to professional libraries (like Moment.js or Day.js).
Best Practices: How to Store? How to Display?
1. Storage Layer (Database)
Always store UTC time only, or directly store the Unix Timestamp (BigInt).
Never store strings like 2023-10-31 10:00:00 without a time zone, unless you're certain your business will never go global.
2. Transmission Layer (API)
When the backend sends data to the frontend, it's recommended to use the ISO 8601 format (with time zone info):
2023-10-31T10:00:00Z (Z stands for UTC)
Or simply provide the timestamp.
3. Display Layer (Frontend)
After the frontend gets the UTC time, it should convert and display it according to the user's local browser time zone.
This way, the user in China sees 10:00, and the boss in the US sees 21:00 (the previous day)—everyone is happy.
What to Do with Mysterious Data?
Sometimes when connecting to third-party APIs, they give you a strange number. You're not sure if it's seconds or milliseconds, nor are you sure which time zone it's in.
When that happens, don't guess—use a tool.
The Timestamp Converter on this site can help you:
- 🔄 Smart Recognition: Automatically detects whether it's seconds or milliseconds.
- 🌍 Multi-timezone Comparison: Simultaneously displays local time, UTC time, and any other time zone you care about.
- ⚡️ Two-way Conversion: Convert date to timestamp or timestamp to date with one click.