Unix Timestamps: The Three Bugs Hiding Inside One Number
How a 10-digit and a 13-digit number get confused, why the same date string produces different timestamps on different machines, and what actually happens in 2038.
What this guide covers
- 1. Bug one: the unit is not in the number
- 2. Bug two: the same date string, two different answers
- 3. Bug three: range, negatives and the 2038 line
- 4. A four-step routine for reading a timestamp from a log
- 5. How to store and name timestamps
- 6. Frequently asked questions
- 7. The one-line version
A Unix timestamp is a single integer with no formatting, no locale and no ambiguous month names. It looks like the safest way to represent a moment in a log line, an API response or a database column. It is also the carrier of three separate bugs that routinely survive code review, because each one produces a plausible-looking answer rather than an error.
The Timestamp Converter on this site displays UTC and local time side by side and states which unit it detected. Both of those are deliberate responses to the problems below.
Bug one: the unit is not in the number
Unix time is conventionally a count of seconds since 1970-01-01T00:00:00Z. JavaScript's `Date.now()` returns milliseconds. Both are plain integers, and both appear constantly in the same log files: a backend writes seconds, a frontend writes milliseconds, and the two get aggregated without anyone noticing. Today a seconds value has ten digits and a milliseconds value has thirteen, so the difference looks obvious — until a converter tries to infer it.
- Choose a magnitude boundary, not a digit-count ceiling. `1e11` separates today's ten-digit seconds from thirteen-digit milliseconds, and covers millisecond values back to 1973 and second values forward past the year 5000.
- State the detected unit in the output. Any heuristic can be wrong at the edges; a silent guess is the actual defect, not the guess itself.
- Watch for other units. Microseconds (16 digits) and nanoseconds (19 digits) are common in tracing systems and high-resolution logs. Do not extend a seconds-or-milliseconds heuristic to cover them — read the producer's contract.
- Put the unit in the field name: `created_at_ms`, not `created_at`. This single naming habit removes an entire class of incident.
Bug two: the same date string, two different answers
Converting a human date into a timestamp has the opposite problem: the input carries no timezone. A `datetime-local` form field produces something like `2026-11-10T09:30`, with no `Z` and no offset. Passing that to `new Date(...)` makes the browser parse it in its own local timezone. On a machine set to UTC+8 the result is 01:30 UTC; on a machine set to UTC+0 it is 09:30 UTC. Same string, same code, timestamps eight hours apart.
This is why the converter deliberately prints both `toISOString()` (always UTC) and `toString()` (the browser's local zone). Seeing `2026-11-10 01:30:00 UTC` next to a local rendering of `09:30` makes the gap explicit rather than letting one of them look authoritative on its own. It is also why a stored timestamp should always be UTC and only be converted at the display boundary — the World Clock exists because computing offsets from memory, especially around daylight saving, is the other half of this bug.
- Store UTC, display local. Never store a local wall-clock time without an offset alongside it.
- Make the offset explicit in any string you pass across a boundary: append `Z` or `+08:00`. A bare datetime is ambiguous by definition.
- Put the timezone in invitations and logs, not just the hour. '14:00 UTC+8' survives a reader in another country; '2pm' does not.
Bug three: range, negatives and the 2038 line
The well-known 2038 problem is an overflow in systems that store `time_t` as a signed 32-bit integer: the largest representable second is 2^31−1, reached at 2038-01-19T03:14:07Z. JavaScript is not affected — `Date` stores milliseconds in a double and covers roughly ±8.64e15 ms, or about 273,790 years either side of the epoch. But a timestamp rarely lives only in JavaScript. It crosses into a C service, a database column typed as `INT`, or an API contract with a 32-bit assumption somewhere downstream, and the failure appears at that boundary rather than in your code.
- Negative values are legal. `−86400` is 1969-12-31T00:00:00Z. Validators that reject any negative number are wrong, and historical or backfilled data is where this surfaces.
- Check `isNaN(date.getTime())`, not truthiness. An invalid `Date` is still an object, so a simple existence check passes while every method returns NaN.
- Zero is a real value. 1970-01-01 is not 'unset'; sentinel values and falsy checks collide here more often than people expect.
- Seconds truncate. Converting millisecond precision to seconds loses ordering within that second. If log ordering matters, keep the milliseconds or add a sequence number.
A four-step routine for reading a timestamp from a log
When an incident hinges on when something happened, the fastest reliable path is short and boring. The point of each step is to remove one of the three ambiguities above before forming a theory.
- 1. Establish the unit from the producer, not the digits. If that is impossible, use magnitude as a fallback and treat the result as provisional. The Timestamp Converter now names the unit it assumed.
- 2. Read the UTC rendering first. `2025-11-10 18:40:00 UTC` is unambiguous. Only afterwards look at the local rendering to compare against a colleague's screenshot.
- 3. Align with a known event. Compare the UTC instant against the deploy window or the alert time. The Date Difference Calculator is useful when the question is an interval rather than an instant.
- 4. Write the conclusion with its zone attached. 'Created at 01:30 UTC on 11 Nov (09:30 UTC+8)' prevents the same argument from being had again tomorrow.
How to store and name timestamps
- Prefer integer milliseconds in JavaScript services, integer seconds elsewhere, and say which in the schema. Do not mix within one field.
- Always UTC. Store the zone of the *user* separately if you need it; do not bake it into the instant.
- Use ISO 8601 strings at human-facing API boundaries where readability beats compactness, and keep the `Z` on the end.
- Distinguish an instant from a duration. A duration in seconds is not a Unix timestamp, and the Time Converter is the right instrument for it.
Frequently asked questions
Why did a valid-looking timestamp produce a date thousands of years in the future? It was almost certainly milliseconds interpreted as seconds (or the reverse). Check which unit the converter says it detected.
Why do two machines disagree on the same date input? A bare datetime string is parsed in each machine's local timezone. Add an explicit offset.
Is 2038 a problem in JavaScript? Not in `Date` itself, but the systems your value passes through may still use 32-bit time.
Can a timestamp be negative? Yes, for moments before 1970. It is a normal value.
Does the converter need my timezone? It reads it from the browser to show the local rendering alongside UTC. Nothing is sent anywhere; the calculation runs in the page.
The one-line version
The integer is not self-describing: it does not say what unit it counts, which timezone a human typed it in, or how wide the receiving system is. Name the unit, store UTC, display local, and make any guess visible. Everything else about timestamps is arithmetic.
Tools run privately in your browser
Every tool referenced in this guide processes your input in the browser rather than uploading it to a server we operate, and requires no account. A typical single job stays free. Larger batches, history export, and an ad-free page are optional on Pro. A few tools load a processing engine from a CDN on first use; see the privacy policy for details. Browse the full toolbox →