How-To Guides

Unix Timestamp: Seconds vs Milliseconds Explained

Learn how to tell a Unix timestamp in seconds from one in milliseconds, why mixing them up breaks dates, and how to convert correctly.

A Unix timestamp is just a number, and that is exactly what makes it dangerous. The number 1796112000 and the number 1796112000000 describe the same instant — 1 December 2026 at 08:00 UTC — but hand the wrong one to the wrong function and your order date lands in January 1970, or your session expiry lands in the year 57887. The bug is never in the number. It is in the unit, and nothing in the number itself tells you which unit it is.

This guide explains the difference, shows you how to identify the unit of any value, and gives you the exact conversions for JavaScript, Python, and spreadsheets.

What a Unix timestamp actually counts

A Unix timestamp, also called epoch time, counts the time since the Unix epoch: 1 January 1970 at 00:00:00 UTC. The original definition counts in seconds, so 0 is the epoch itself, 86400 is exactly one day later, and negative numbers are dates before 1970 — -86400 is 31 December 1969.

A timestamp represents one exact instant, not a formatted date. The same instant can be displayed as 08:00 in London, 13:00 in Karachi, or 16:00 in Tokyo; the timestamp does not change. A timestamp has no time zone — the time zone only enters when you format it for display. Unix time also pretends every day has exactly 86,400 seconds, ignoring leap seconds.

The trouble is that seconds are not the only unit in use. Many platforms count milliseconds instead, and a JSON field can arrive in either.

Why the units differ

Seconds are the original Unix unit. The C library, date +%s, PHP's time(), Python's time.time(), and most REST APIs all produce seconds. JWT claims such as exp, iat, and nbf are defined in seconds too — a token expiry in milliseconds would be valid for tens of thousands of years, a security problem, not just a display problem.

Milliseconds became common because Java and JavaScript chose them. Java's System.currentTimeMillis() returns milliseconds, and JavaScript's Date works in milliseconds throughout: Date.now() returns milliseconds and new Date(value) expects them. Because so much of the web runs on JavaScript, millisecond timestamps are now everywhere — in browser code, analytics events, logging pipelines, and JSON from Node.js services. Higher precisions exist too: some tracing systems use microseconds (16 digits today) and Go's UnixNano() returns nanoseconds (19 digits). In practice, seconds and milliseconds are the two you will meet — and the two that get confused, because the millisecond form of any instant is the seconds form with three extra zeroes.

Identify the unit

When a bare number lands in your code or a log file, work out its unit before you use it. These checks settle nearly every case.

Count the digits

For dates near today, digit count is the fastest check. A current timestamp in seconds has 10 digits; in milliseconds, 13; in microseconds, 16; in nanoseconds, 19. The instant 1 December 2026 at 08:00 UTC is 1796112000 in seconds and 1796112000000 in milliseconds. Treat this as a first glance, not a law: a seconds value for the year 2286 has 11 digits, and a milliseconds value for a date in 1973 has only 11.

Use the 1e11 threshold

A more robust rule, and the one converters use, is a magnitude threshold: any absolute value of 100,000,000,000 (1e11) or more is treated as milliseconds, and anything below it as seconds. The cut is safe in both directions: 1e11 seconds would be the year 5138, so no realistic date in seconds is ever that large, and 1e11 milliseconds is 3 March 1973, so almost no date in milliseconds is ever that small. FBSubNet's Unix Timestamp Converter applies exactly this rule.

Convert both ways and see which one makes sense

When you are still unsure, convert the value both ways and keep the result that describes a sensible date. 1796112000 read as seconds is 1 December 2026 at 08:00 UTC; read as milliseconds it is 21 January 1970. 1796112000000 read as milliseconds is 1 December 2026 at 08:00 UTC; read as seconds it is the year 57887. The wrong reading is almost always absurd, and that absurdity is itself the diagnosis. When documentation is available, check it first: an API reference that says "epoch seconds" settles the question without guessing.

Worked demo: one instant, two numbers, two wrong dates

Take one instant and follow it through both units, then through both mistakes. The instant is 1 December 2026 at 08:00:00 UTC: 1796112000 in seconds (10 digits) and 1796112000000 in milliseconds (13 digits). Both describe the same moment.

Mistake 1: seconds read as milliseconds

JavaScript's Date constructor expects milliseconds. Passing the seconds value directly gives:

new Date(1796112000)
// 1970-01-21T18:55:12.000Z

The date collapses to 21 January 1970: the value was read as 1,796,112,000 milliseconds after the epoch — about 20 days — instead of 1,796,112,000 seconds, about 57 years. This is the most common timestamp bug on the web, and it never throws an error. If you ever see a real-world date rendered as mid-January 1970, this is almost certainly the cause. The fix is one multiplication:

new Date(1796112000 * 1000)
// 2026-12-01T08:00:00.000Z

Mistake 2: milliseconds read as seconds

The reverse mistake is louder. Feed the 13-digit value to something that expects seconds — Python's datetime.fromtimestamp(), for example — and the result is the year 57887, beyond the range most date libraries can represent. The fix is one division:

from datetime import datetime, timezone
datetime.fromtimestamp(1796112000000 / 1000, tz=timezone.utc)
# 2026-12-01 08:00:00+00:00

The wrong answer is always off by a factor of 1,000 in time — the difference between 57 years and 20 days, or between 57 years and 57,000 years. There is no subtle version of this bug. If a date looks wildly wrong, check the unit first. You can repeat this demo yourself: paste either number into the Unix Timestamp Converter and it shows the UTC time, the epoch seconds, the epoch milliseconds, and your local time side by side.

Convert correctly

Once you know the unit, conversion is simple arithmetic — multiply by 1,000 going from seconds to milliseconds, divide by 1,000 going the other way.

JavaScript

JavaScript works in milliseconds everywhere, so seconds must be multiplied by 1,000 on the way in and divided on the way out:

const seconds = 1796112000;
const date = new Date(seconds * 1000);        // seconds -> Date
console.log(date.toISOString());              // 2026-12-01T08:00:00.000Z

const nowMs = Date.now();                     // milliseconds
const nowSeconds = Math.floor(nowMs / 1000);  // milliseconds -> seconds

Use Math.floor when dividing, not Math.round, which can push a timestamp into the next second. Never pass a seconds value to new Date() without multiplying — the constructor will not warn you.

Python

Python's datetime works in seconds, with fractions for anything smaller, so milliseconds must be divided by 1,000 first:

from datetime import datetime, timezone

ts_seconds = 1796112000
dt = datetime.fromtimestamp(ts_seconds, tz=timezone.utc)

ts_ms = 1796112000000
dt_ms = datetime.fromtimestamp(ts_ms / 1000, tz=timezone.utc)

Always pass tz=timezone.utc to fromtimestamp. Without it, Python uses your machine's local time zone, which gives a different wall-clock reading on every machine.

Spreadsheets and SQL

Spreadsheets store dates as serial day numbers. In Excel or Google Sheets, with a seconds value in A1, use =A1/86400 + DATE(1970,1,1) for seconds and =A1/86400000 + DATE(1970,1,1) for milliseconds, then format the cell as a date-time. In SQL, PostgreSQL's to_timestamp() and MySQL's FROM_UNIXTIME() expect seconds, so divide milliseconds first: SELECT to_timestamp(1796112000000 / 1000);.

Normalise at the boundary

If your code accepts timestamps from more than one source, normalise them once, where the data enters your system:

function normalizeTimestamp(value) {
  const n = Number(value);
  // Above 1e11 means we are already in milliseconds
  const seconds = Math.abs(n) > 1e11 ? n / 1000 : n;
  return new Date(seconds * 1000);   // works for both 10 and 13 digits
}

normalizeTimestamp(1796112000);     // 2026-12-01T08:00:00.000Z
normalizeTimestamp(1796112000000);  // 2026-12-01T08:00:00.000Z

Where each unit shows up

Seconds come from Unix date +%s, PHP time(), Python time.time(), most REST APIs, JWT exp / iat / nbf claims, and MySQL TIMESTAMP. Milliseconds come from JavaScript Date.now(), Java System.currentTimeMillis(), .NET ToUnixTimeMilliseconds(), and many analytics and logging pipelines. Microseconds appear in PostgreSQL internals and some tracing systems; nanoseconds in Go's UnixNano() and Python's time.time_ns().

APIs deserve a special note: JSON has no date type, so a timestamp arrives as a bare number with no unit attached. When an API hands you JSON with epoch values, format it first so you can read it — FBSubNet's guide to formatting JSON online shows how to pretty-print a payload and spot the timestamp fields. Then check the API's documentation for the unit.

Common mistakes and how to fix them

The date shows January 1970

Seconds were read as milliseconds. Multiply by 1,000 before constructing the date, or check whether the value arriving at your code is 10 digits when the consumer expects 13.

The date shows the year 50000 or an out-of-range error

The reverse: milliseconds were read as seconds. Divide by 1,000 before constructing the date. If the value is 13 digits and the consumer expects seconds, this is the bug.

Storing milliseconds in a 32-bit integer

A signed 32-bit integer tops out at 2,147,483,647 — 19 January 2038 at 03:14:07 UTC in seconds. After that the counter wraps to a negative number, read as December 1901: the Year 2038 problem. In milliseconds, 2,147,483,647 is only 25 days after the epoch, so any field holding a millisecond timestamp must be 64-bit.

A naming habit that prevents the bug

Every fix in this article is a conversion at a boundary, and every bug is a place where the unit was unknown. Make the unit visible wherever a timestamp is stored, passed, or documented:

  • Name the unit in the field or variable: createdAtMs, expires_at_s, eventTimeMillis. A reader should never have to guess.
  • Convert at the boundary: normalise to one unit where data enters your system — usually milliseconds in JavaScript, seconds in Python and SQL — and keep that unit everywhere inside it.
  • Document the unit in the API: a field documented as "Unix timestamp in seconds" cannot be misread; one documented as "timestamp" will be.
  • Store one unit per column: never mix seconds and milliseconds in the same database column, and write the unit in the column comment if the name cannot carry it.
  • Test with a known instant: assert that your code produces 1796112000 seconds and 1796112000000 milliseconds for 1 December 2026 at 08:00 UTC.

Frequently asked questions

How many digits is a Unix timestamp in seconds?

Ten digits for any date between September 2001 and November 2286; a current timestamp in milliseconds has 13 digits. Confirm with the 1e11 threshold for dates far from today.

Does a Unix timestamp have a time zone?

No. A Unix timestamp is a count since 1 January 1970 at 00:00:00 UTC, and it identifies one instant. Time zones only apply when you format that instant as a readable date and time.

Should I use seconds or milliseconds in my own API?

Use seconds unless you need sub-second precision — seconds are the original Unix definition and what JWT claims use. If you need milliseconds, say so in the field name and the documentation, and be consistent across every endpoint.

The short version

A Unix timestamp is a count since 1 January 1970, and the only thing you must know about any given value is its unit. Seconds are the classic unit — 10 digits today — and milliseconds are the JavaScript and Java convention — 13 digits today. Mix them up and the date lands in January 1970 or tens of thousands of years in the future, off by exactly 1,000×. Count the digits, apply the 1e11 threshold when in doubt, and name the unit in your variables. To check a value quickly, paste it into the Unix Timestamp Converter.