Unix timestamp guide | UnixDate

Developer guide for working with Unix timestamps safely and predictably.

Unix milliseconds vs seconds

The most common time bug in APIs is mixing Unix seconds (10 digits) with Unix milliseconds (13 digits). Browsers often emit milliseconds, while backends store seconds.

Reliable detection

  • ~10 digits → seconds
  • ~13 digits → milliseconds
  • ~16 digits → microseconds (less common)

Safe normalization

If you accept input from multiple clients, normalize values: if the number is greater than 9999999999, treat it as milliseconds and divide by 1000 (floor).

Common mistakes

  • Storing ms in a seconds column (dates jump to year 51382+)
  • Multiplying seconds by 1000 twice in JS
  • Parsing as a string and losing precision in floating conversions