The integer that will not say what it means
A JSON payload hands you created_at: 1700000000 and moves on. The number is unambiguous as arithmetic and completely ambiguous as time. As seconds since the epoch, it resolves to 2023-11-14T22:13:20Z. As milliseconds, it resolves to 1970-01-20T16:13:20Z. As microseconds it lands about twenty-eight minutes after midnight on January 1, 1970; as nanoseconds, under two seconds after. The integer carries no unit, no signpost — whatever meaning it has was decided by whoever wrote the serialization code, and that decision lives in documentation, convention, or tribal memory.
The failure mode survives because in the common case the eyeball heuristic gives the right answer. It shows up at the edges: old data, unusual units, a new endpoint whose author chose differently, or a value already converted once on its way to you.
Why digit counting almost works
The folk heuristic goes: ten digits means seconds, thirteen means milliseconds, sixteen means microseconds, nineteen means nanoseconds. Each factor of one thousand adds three digits, and since the epoch began in 1970 while the present sits a fixed distance away, the digit count of "now" in each unit is indeed fixed. It is genuinely useful for forming a suspicion about an unfamiliar value; the trouble starts when the suspicion hardens into an assumption that ships to production.
Where the heuristic breaks
It breaks in three ways. First, the boundaries of each digit band are fixed distances from 1970, not "recent dates." A ten-digit number is any second count up to 9,999,999,999, but also any millisecond count up to about 9.99 billion — covering only the first 115 days of 1970. So a ten-digit millisecond timestamp genuinely exists, and the "ten digits means seconds" rule reads it as a date over three centuries away. The overlap repeats one band up: a thirteen-digit value is usually milliseconds from 2001 onward, but also a microsecond value from the spring of 1970.
Second, negative values do not fit the pattern at all. A timestamp before 1970 — a historical birth date, a backdated audit entry — is negative, and its digit count says nothing useful. Third, fractional serialization: some APIs send seconds as a decimal like 1700000000.512, which carries thirteen significant digits — the signature the heuristic reads as milliseconds — except this value really is seconds, and multiplying it by 1000 would corrupt it. The table below summarizes the overlap.
| Digit pattern (positive values) | Plausible units | Failure mode when guessed wrong |
|---|---|---|
| 1–9 digits | Seconds before Sep 2001; milliseconds only within the first ~11.5 days of 1970 | Assuming milliseconds throws the date back to January 1970 |
| 10 digits | Seconds from 2001 to 2286 — or milliseconds from Feb–Apr 1970 | The "10 digits = seconds" rule reads an April-1970 millisecond value as the year 2286 |
| 11–12 digits | Milliseconds from 1970 to 2001 | Read as seconds, dates land centuries to millennia in the future |
| 13 digits | Milliseconds from 2001 to 2286 — or microseconds from Apr 1970 | The "13 digits = milliseconds" rule misreads early microsecond values by a factor of 1000 |
| 16 digits | Microseconds from 2001 to 2286 — or nanoseconds from Apr 1970 | Same overlap one band up; the largest values also exceed JavaScript's safe integer range |
| 19 digits | Nanoseconds from 2001 to 2262 (the signed 64-bit limit) | Far beyond JavaScript's safe integer range — the last digits silently round |
Values with a minus sign or a decimal point fit none of these bands cleanly — digit counting is a starting point, never a conclusion.
The thousandfold error, up close
A wrong-by-a-thousand guess does not produce subtly wrong dates. They are absurd in one of two directions — the one mercy of this bug is that the symptoms are loud if anyone looks.
Dates frozen in January 1970
Take a seconds value and divide it by 1000 — the standard "correction" applied by code that expects milliseconds — and a date in the 2020s collapses into the first weeks of 1970:
from datetime import datetime, timezone
value = 1700000000 # seconds: 2023-11-14T22:13:20Z
datetime.fromtimestamp(value, tz=timezone.utc)
# 2023-11-14 22:13:20+00:00 (correct)
datetime.fromtimestamp(value // 1000, tz=timezone.utc)
# 1970-01-20 16:13:20+00:00 (divided a seconds value)
Databases quietly fill up with rows stamped 1970-01-20 or, where a zero or empty value got divided, 1970-01-01. Sorting still works, charts still render, nothing crashes — which is why these rows survive for months while anything filtering "since last week" silently misses them.
Dates fifty thousand years out
Run the error the other way — treat a millisecond value as seconds, or multiply an already-converted value again — and the date lands absurdly in the future:
const ms = 1700000000000; // 2023-11-14T22:13:20Z in milliseconds
new Date(ms).toISOString();
// "2023-11-14T22:13:20.000Z" (correct)
new Date(ms * 1000).toISOString();
// a date in the year 55827 — over fifty thousand years out
Dates like this almost never reach a human. They break sorting, overflow chart axes, and trip validation ranges — or, worse, they get clamped: some libraries silently clamp out-of-range dates to their maximum, turning a loud error into a plausible-looking wrong answer.
The quiet variant: truncation
A subtler sibling never produces an absurd date at all. Integer division truncates: 1,700,000,512 milliseconds divided by 1000 with integer arithmetic gives 1,700,000 seconds, and the 512 milliseconds vanish without a trace. Applied across a dataset, truncation systematically biases every timestamp downward, and inside a loop sampling a rising clock it can make events appear out of order. Wherever sub-second precision carries meaning, truncation is a correctness bug.
Establishing the unit from context
Since the number cannot speak for itself, the unit question is really a documentation question — and context almost always contains the answer if you know where to look.
The API contract is the only real authority
A field's unit is part of its contract, and a contract that does not state the unit is incomplete. Well-designed APIs spell it out in the schema: an OpenAPI description that says created_at (integer, seconds since Unix epoch) removes the guesswork entirely. The problem-details convention shows the same discipline — its date fields are ISO 8601 strings precisely so no unit question can arise. If you publish an API, stating the unit for every time field, or better sidestepping the issue with an ISO string, is the cheapest fix available. Our guide on machine-readable error responses shows this applied to error payloads.
Sibling fields as evidence
When documentation is missing, other fields often settle the question. A response containing both expires_in: 3600 and created_at: 1700000000 tells you two things: OAuth's expires_in is contractually seconds, and payload authors rarely mix units within one response. An explicit suffix is direct testimony — created_at_ms or ts_ns ends the debate. Backend heritage is a weaker but real signal: Java backends commonly emit milliseconds, Python backends commonly emit seconds.
HTTP headers and known anchors
Headers follow different rules than bodies: caching directives like max-age are always seconds, while Date and Last-Modified are formatted strings, never epoch numbers. Our guide on JSON in HTTP headers covers these conventions. The most decisive evidence, though, is a paired value you already understand. If the payload includes any field whose true time you can verify independently, convert the mystery value both ways and see which interpretation agrees with the anchor. One anchored pair settles the unit for the entire API, because serializers do not change units from request to request.
Extract the field without damaging it
In a deeply nested response, the practical first step is pulling out the candidate value with full precision intact. JSON Pointer paths address a nested field exactly — /data/created_at — because a value copied through a console or a truncated log line can lose digits or pick up formatting on the way to conversion. Our guide on JSON Pointer escapes explains how to address fields whose names contain awkward characters.
What the epoch actually measures
A Unix timestamp counts units elapsed since 1970-01-01T00:00:00Z — midnight on January 1, 1970, in UTC, not in any local timezone. The Z matters: the epoch is anchored to UTC, so the same integer is simultaneously 8 PM the previous evening in New York and 9 AM on January 1 in Tokyo. ISO 8601 strings describe the same instants, with the precision spelled out in the string itself:
2023-11-14T22:13:20Z # second precision, UTC
2023-11-14T22:13:20.512Z # millisecond precision
2023-11-14T22:13:20-05:00 # explicit offset; same instant as 2023-11-15T03:13:20Z
Two details of the definition matter in practice. First, leap seconds are excluded. Real UTC occasionally inserts a leap second — twenty-seven so far — to stay aligned with Earth's rotation, but Unix time ignores them: every day is exactly 86,400 seconds long. Unix time can therefore disagree with an atomic clock by up to the accumulated leap-second total — irrelevant for most applications, critical for satellite-navigation comparisons.
Second, the timeline extends backward: a timestamp of -86400 is 1969-12-31T00:00:00Z. Negative values are legal and correctly represent pre-1970 instants. The trap is the arithmetic around them: conversions that floor behave differently on negatives than conversions that truncate toward zero, and code tested only against modern dates can be off by a full unit at the epoch boundary and before it:
const ts = -86400; // one day before the epoch
new Date(ts * 1000).toISOString();
// "1969-12-31T00:00:00.000Z"
const frac = -1500; // milliseconds, pre-epoch
Math.floor(frac / 1000); // -2 (floor: the containing second)
Math.trunc(frac / 1000); // -1 (truncation: a second too late)
Fractional seconds versus integer milliseconds
A third representation lurks between the two familiar units: seconds with a fractional part. Several prominent APIs serialize timestamps as decimals like 1700000000.512 — seconds, with sub-second precision carried in the fraction. This format is more self-describing than any integer timestamp: the decimal point is a visible marker that the value is in seconds, since an integer millisecond count never has a fractional part.
The sharp edge is precision. A binary floating-point number holds about fifteen to sixteen significant decimal digits, and a seconds value with three fractional digits at today's epoch magnitudes needs sixteen — right at the edge. That is why some fractional values survive a float round-trip untouched and others come back with garbage in the last digit, and garbage in the last digit of a millisecond field is still a wrong timestamp.
from decimal import Decimal
raw = "1700000000.512" # seconds with milliseconds, as sent
Decimal(raw) * 1000 # Decimal('1700000000512.000') — exact
float(raw) * 1000 # may print 1700000000511.9998… — binary drift
Nanoseconds and JavaScript: a nanosecond timestamp at today's epoch — about 1.7 × 1018 — exceeds Number.MAX_SAFE_INTEGER, roughly 9.0 × 1015. A JavaScript number cannot hold such a value exactly; the final digits silently round on assignment. If an API sends nanoseconds, treat the value as a string or a BigInt — never a plain number.
Why silent rounding is dangerous
Silent rounding sounds harmless — who cares about a millisecond? — but sub-second digits often carry semantic weight. Two events fifty milliseconds apart collapse onto the same rounded second, and any logic built on ordering — last-write-wins, event sourcing, deduplication — silently misorders them, while deduplication keys derived from rounded timestamps collide and drop distinct records as apparent duplicates. The rule is simple: convert exactly, and if rounding is genuinely needed, do it once, deliberately, at a named step.
Timezones are a display concern, not a storage concern
Unit confusion gets most of the attention, but its neighbor bug — timezone confusion — produces errors just as misleading, and the two often show up in the same debugging session. The principle that prevents the second bug is short: timestamps are instants; timezones are presentations. An integer timestamp identifies a moment with no location attached. Showing that moment as 22:13 UTC, 2:13 PM Pacific, or 07:13 the next morning in Tokyo is a rendering decision that belongs exclusively to the display layer.
Storage should therefore always be UTC — which, for epoch integers, happens automatically. The classic violation is formatting a timestamp into a string using a server's local timezone, storing that string, and reading it back on a different server or after a timezone rule change. The string has thrown away the instant and kept only one presentation of it. Store the instant; render the presentation at the edges of your system, as late as possible, using the viewer's timezone.
DST and ambiguous local times
Rendering is one-way and safe: an instant plus a timezone rule always yields exactly one local time. The reverse direction is where daylight saving time bites. Converting a calendar date and wall-clock time back into a timestamp, some local times do not exist (the spring-forward hour) and others occur twice (the fall-back hour). In the New York timezone, 01:30 AM on the November fall-back morning happens twice, an hour apart — and code that converts it without saying which occurrence it means silently picks one.
from datetime import datetime, timezone
from zoneinfo import ZoneInfo
ny = ZoneInfo("America/New_York")
wall = datetime(2025, 11, 2, 1, 30) # 01:30 local, fall-back morning
first = wall.replace(tzinfo=ny, fold=0).astimezone(timezone.utc)
# 2025-11-02 05:30:00+00:00 (the first 01:30, still on EDT)
second = wall.replace(tzinfo=ny, fold=1).astimezone(timezone.utc)
# 2025-11-02 06:30:00+00:00 (the second 01:30, after the switch)
The same wall-clock string maps to two instants an hour apart. Any system accepting local times from users — schedulers, booking forms, log ingestion — must either demand an explicit offset in the input or define, and document, which occurrence it chooses. ISO 8601 strings with explicit offsets sidestep the problem entirely: 2025-11-02T01:30:00-04:00 and 2025-11-02T01:30:00-05:00 are different strings for the two occurrences.
Practical strategies that hold up in production
The individual failure modes have individual fixes, but three habits prevent nearly every timestamp bug in this family.
Normalize at the boundary
Convert every incoming timestamp to your internal representation exactly once, at the point where data enters your system — the API handler, the ingestion job, the parser. Everything downstream works with one known unit and never re-derives it. The boundary function should make its rules explicit, even when those rules are only documented heuristics:
# Boundary normalization pseudocode.
# Internal representation: integer milliseconds since the epoch.
function to_internal_ms(raw):
if raw is a string containing ".":
return decimal_seconds_to_ms(raw) # "1700000000.512" -> 1700000000512
n = parse_exact_integer(raw) # never through a floating-point step
m = absolute_value(n)
if m > 10^14:
fail "fits neither seconds nor milliseconds — inspect manually"
if m > 10^11:
return n # 12 to 14 digits: already milliseconds
return n * 1000 # shorter: seconds; the sign survives
The exact thresholds matter less than the shape of the solution: one function, one set of rules, applied everywhere data arrives. A thousandfold error is almost always two pieces of code each converting "to be safe," or one conversion applied twice on a single path.
Pick one internal representation and defend it
Whatever you choose — integer seconds, integer milliseconds, or ISO 8601 strings — choose it once, write it down, and make departures loud. Integer milliseconds are the pragmatic default for many teams: sub-second precision survives, the values fit comfortably in a signed 64-bit integer, and they interoperate cleanly with Java and JavaScript conventions. What loses in every case is the undeclared mixture — two services in one pipeline, one sending seconds and one sending milliseconds, both fields named timestamp.
Validate explicitly instead of guessing silently
Where the unit truly cannot be established, the worst move is a quiet guess and the second worst is an assertive guess that fails on rare data. The workable middle is explicit validation with a wide but real sanity window: values that could plausibly be either unit get flagged for review, and values that fit no unit fail loudly. Ambiguity then surfaces at the boundary as a logged event instead of surfacing three months later as a January 1970 spike in a quarterly report.
A debugging checklist for a timestamp that looks wrong
When a date in your system is impossible — stuck in 1970, absurdly far in the future, off by a factor of a thousand, or off by an hour or a day — work down this list.
- Find the raw value. Look at the timestamp before any transformation touched it: the original response body, the raw log line, the database column.
- Compute both interpretations. Convert the raw value as seconds and as milliseconds and compare each against what the system displayed. One will usually match the wrong output, telling you where in the pipeline the bad conversion happened.
- Count conversions, not just their results. Search the path for multiplication and division by 1000,
toMillis-style calls, and date formatting. Two conversions on one path is the classic double error. - Compare against an anchored sibling. Find any field whose true time you know independently, and check which interpretation agrees with it.
- Check the renderer's timezone. If the date is off by hours rather than thousands of years, the unit is probably fine and the display timezone is not.
- Classify off-by-one patterns. A one-hour error smells like DST or a missing offset; a one-day error smells like a calendar-day boundary crossed during rendering.
- Test the edges. Pre-1970 negative values, fractional strings parsed as integers, and zero values formatted into 1970-01-01 all produce plausible-looking but wrong output.
- Fix at the boundary, not at the symptom. Correct the conversion where data enters the system, normalize existing bad rows deliberately, and write the unit into the field documentation.
Test it yourself
Every claim in this guide is checkable in a browser tab. Paste a mystery integer into the Timestamp Explorer and read it as seconds and as milliseconds side by side — the thousandfold error in both directions is visible at a glance, negative pre-epoch values resolve correctly, and fractional-second strings show their rounding behavior. For timestamp fields buried inside a large API response, the JSON Inspector extracts the raw value with full precision, so digits are never lost to display formatting on the way to conversion.
Reproduce every example locally with the JSON Inspector or the matching tool on the workbench. Nothing you paste leaves your browser.