Epoch Milliseconds to Date: Convert 13-Digit Timestamps and Long Values

A guide to converting epoch milliseconds to readable dates. Covers 13-digit timestamps, JavaScript Date, Java long values, milliseconds vs seconds, and why the wrong unit produces 1970 or far-future dates.

What epoch milliseconds are

Epoch milliseconds count milliseconds since January 1, 1970 at 00:00:00 UTC. They use the same Unix epoch as Unix seconds, but with three extra digits of precision. A modern epoch milliseconds value is usually 13 digits, such as 1700000000000.

How to convert millis to date

If the value is already milliseconds, JavaScript Date can read it directly. If the receiving tool expects seconds, divide by 1000 first. The main mistake is multiplying or dividing at the wrong boundary.

  • JavaScript: new Date(1700000000000).toISOString()
  • Milliseconds to seconds: Math.floor(1700000000000 / 1000)
  • Seconds to milliseconds: 1700000000 * 1000
  • Java Instant: Instant.ofEpochMilli(1700000000000L)
  • Python: datetime.fromtimestamp(ms / 1000, tz=timezone.utc)

Long to date in Java and databases

Searches for long to date often come from Java, Kotlin, Android, or database exports where a timestamp is stored as a 64-bit integer. The value might be epoch milliseconds, but it can also be seconds, microseconds, or nanoseconds. Check the number of digits before converting.

  • 10 digits: likely Unix seconds
  • 13 digits: likely Unix milliseconds or Java long milliseconds
  • 16 digits: likely microseconds
  • 19 digits: likely nanoseconds
  • Always name columns with units, such as created_at_ms

Why milliseconds convert to strange dates

A milliseconds value treated as seconds becomes an extremely far-future date. A seconds value treated as milliseconds becomes a date near January 1970. The digits are the quickest diagnostic.

  • 1700000000000 as milliseconds = 2023-11-14 22:13:20 UTC
  • 1700000000000 as seconds = year 55840 range, depending on the library
  • 1700000000 as seconds = 2023-11-14 22:13:20 UTC
  • 1700000000 as milliseconds = 1970-01-20 16:13:20 UTC

Epoch milliseconds FAQ

Is epoch time in ms the same as Unix timestamp?
It uses the same epoch, but the unit is milliseconds instead of seconds. Classic Unix timestamp usually means seconds.
How many digits is an epoch millisecond timestamp?
For current dates, epoch milliseconds are usually 13 digits.
Does JavaScript use milliseconds or seconds?
JavaScript Date uses milliseconds. Date.now() returns epoch milliseconds.
How do I convert a Java long timestamp to a date?
If the long is epoch milliseconds, use Instant.ofEpochMilli(value); if it is epoch seconds, use Instant.ofEpochSecond(value). Check the digit count first — 13 digits is usually milliseconds, 10 digits is usually seconds.