Guessing whether a Unix timestamp is in seconds or milliseconds from its digit count
A timestamp such as 1700000000 can mean November 2023 in seconds or January 1970 if misread as milliseconds, a mistake that can slip past code review. The article notes that seconds usually have 10 digits, milliseconds 13, microseconds 16 and nanoseconds 19, so digit count offers a usable guess at the unit. A converter tool applies this rule with cut points between common lengths and still lets users select the unit manually. JavaScript numbers lose precision beyond 2^53, so the tool keeps input as BigInt and divides down only at the end, and it uses floor division for dates before 1970. It also flags values beyond the Date range as out of range instead of displaying an invalid date.
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