Seconds vs Milliseconds Timestamps

Understand the difference between second and millisecond Unix timestamps. Learn to detect, convert, and avoid common bugs with timestamp precision.

Concept

1700000000 vs 1700000000000

Detailed Explanation

One of the most common sources of timestamp bugs is confusing seconds-based and milliseconds-based timestamps. A seconds timestamp like 1700000000 represents November 14, 2023, while the same digits with three trailing zeros (1700000000000) as a millisecond timestamp represents the same moment, just with finer precision.

How to tell them apart:

The simplest heuristic is digit count. As of the 2020s, a seconds-based Unix timestamp has 10 digits, while a milliseconds timestamp has 13. This rule holds reliably from the year 2001 through 2286.

10 digits → seconds      (e.g., 1700000000)
13 digits → milliseconds (e.g., 1700000000000)
16 digits → microseconds (e.g., 1700000000000000)
19 digits → nanoseconds  (e.g., 1700000000000000000)

Which languages use which:

Unit Languages/Systems
Seconds Python, PHP, Ruby, Bash, Go, C, MySQL
Milliseconds JavaScript, Java, Dart, C# (DateTimeOffset)

Conversion between them:

// Milliseconds to seconds
const seconds = Math.floor(milliseconds / 1000);

// Seconds to milliseconds
const ms = seconds * 1000;

Common bug scenario: You store a JavaScript Date.now() value (milliseconds) in a database and then read it in a Python script that expects seconds. The Python code interprets it as a date tens of thousands of years in the future. The fix is to always document your timestamp unit at the API boundary and convert consistently.

API design tip: When designing APIs, explicitly state the unit in your field name (e.g., created_at_ms or expires_at_unix_seconds). This prevents ambiguity and saves hours of debugging for consumers of your API. Many modern APIs, including Stripe and Twilio, use seconds-based timestamps and document this clearly.

Use Case

Debugging why a newly created resource shows an expiration date of year 55,000 is almost always a seconds-vs-milliseconds mix-up between your frontend JavaScript and backend Python code.

Try It — Timestamp Converter

Open full tool