51NAV
Explained

Unix Timestamp: 10 Digits or 13? Seconds vs Milliseconds

A Unix timestamp is either 10 digits (seconds) or 13 (milliseconds). Mixing them up shifts dates by a factor of 1000 — here is how to tell and convert.

3 min read Beginner
#timestamp #unix #date #debugging
Table of Contents

The two flavors

A Unix timestamp counts seconds (or milliseconds) since 1970-01-01T00:00:00Z.

UnitDigits (now)Example
Seconds101780000000
Milliseconds131780000000000

The bug

Code that expects seconds but gets milliseconds (or the reverse) is wrong by exactly 1000×:

const exp = 1780000000;          // seconds (JWT-style)
const now = Date.now();          // milliseconds
// WRONG: compares ms to seconds
if (now > exp) { /* always true */ }

// RIGHT: same unit
if (Math.floor(now / 1000) > exp) { /* correct */ }

How to tell which you have

  • 10 digits → seconds.
  • 13 digits → milliseconds.
  • If a “timestamp” is 1.78e12, it is milliseconds.

Convert

const sec = Math.floor(Date.now() / 1000);     // ms -> s
const ms  = sec * 1000;                         // s -> ms

Watch JWT and databases

  • JWT exp/iat/nbf are seconds.
  • JavaScript Date.now() is milliseconds.
  • SQL FROM_UNIXTIME() usually expects seconds; unix_timestamp() returns seconds.

Convert any value

Paste a timestamp and see the date in both units with the Timestamp Converter on Toolbox.

Next steps

Frequently asked questions

How do I know if a timestamp is seconds or ms?

Count digits. 10 digits (up to 2147483647) is seconds; 13 digits is milliseconds. A value like 1780000000 is seconds; 1780000000000 is milliseconds.

Why does my date show as 1970 or the year 52000?

You passed milliseconds into something expecting seconds (or vice versa). The result is off by 1000x: seconds-treated-as-ms lands in 1970; ms-treated-as-seconds jumps past the year 50000.

What does JavaScript use?

Date.now() returns milliseconds (13 digits). Many backend claims like JWT exp are seconds (10 digits), so convert before comparing.

Guide Info

Category
Explained
Difficulty
Beginner
Reading Time
3 min
Tags
#timestamp #unix #date #debugging

Next guide

URL Space: %20 or +? The Two Encoding Rules

Spaces turn into %20 almost everywhere, but into + inside form data. Knowing which rule applies stops broken links and missing query values.

View Next Guide