Dev · 2 min read ·

Unix timestamps: seconds or milliseconds?

The 13-digit bug that ships to production every week, and a dead-simple heuristic to tell the two units apart.

JavaScript speaks milliseconds. Most backends speak seconds. Mix them up and your dates land in January 1970 — or tens of thousands of years in the future.

Count the digits

A present-day timestamp in seconds has 10 digits (1790000000 is 21 September 2026). The same moment in milliseconds has 13 digits; in microseconds 16 and in nanoseconds 19.

The heuristic

If the absolute value is above 10¹², it is milliseconds; otherwise treat it as seconds. That holds for any millisecond timestamp after September 2001 and any second timestamp before the year 33658.

const ms = Math.abs(n) > 1e12 ? n : n * 1000;

Pick the unit explicitly

The 4Dev timestamp converter doesn't guess: "Unix Timestamp" means seconds and "Unix Timestamp (ms)" means milliseconds, next to microsecond and nanosecond variants — 33 formats in total, including ISO 8601, RFC 2822, SQL DATETIME and Excel serial dates.

Open the timestamp converter