Unix Timestamp Bug Explained: Why Mixing Seconds and Milliseconds Breaks Dates

A common programming bug causes dates to display incorrectly — either as January 1970 or the year 55,840 — when Unix timestamps in seconds are confused with milliseconds, or vice versa. JavaScript's Date object expects milliseconds, so passing a seconds-based timestamp without multiplying by 1,000 results in a date just 19 days past the Unix epoch. Conversely, multiplying a milliseconds timestamp by 1,000 again pushes the date tens of thousands of years into the future. A practical rule of thumb is to count digits: a 10-digit value is likely in seconds, while a 13-digit value is likely in milliseconds. Developers are advised to confirm the unit from API documentation and convert explicitly rather than relying on digit-counting heuristics in production code.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in