Format comparison

FormatExamplePrecisionCommon source
Unix seconds17633112001 sPOSIX, most databases
Unix milliseconds17633112000001 msJavaScript, Java Date
ISO 8601 / RFC 33392025-11-16T14:00:00ZConfigurableJSON APIs, OpenAPI
RFC 2822Sun, 16 Nov 2025 14:00:00 +00001 sEmail, HTTP Date header
SQL timestamp2025-11-16 14:00:00MicrosecondsMySQL, PostgreSQL
Excel serial46037.5833331 daySpreadsheets

Which format should you choose?

  • For storage and APIs: an integer epoch (seconds or milliseconds) or ISO 8601 with an offset. Pick one and document the unit.
  • For logs: ISO 8601 with milliseconds and an explicit offset, so humans and machines can both read it.
  • For user interfaces: localize at render time; never store a localized string.
  • For email headers: RFC 2822 is the required format.
  • For SQL: use the database's timezone-aware type if it has one; otherwise store UTC explicitly.

Precision traps

Mixing units is the most common timestamp bug. A seconds value multiplied by 1000 twice lands in the year 56000; a milliseconds value divided by 1000 once lands in 1970. A second class of bug comes from truncating fractional seconds: two events in the same second become indistinguishable.

RFC 3339 allows an arbitrary number of fractional digits, but many parsers accept only 3 (milliseconds) or 6 (microseconds). If interoperability matters, send exactly three digits.

When in doubt, print both the raw number and the ISO string in logs. It makes unit errors obvious at a glance.

Formatting tokens you will meet

TokenMeaningExample
%YFour-digit year2025
%mZero-padded month11
%dZero-padded day16
%H:%M:%S24-hour time14:00:00
%zNumeric offset+0000
%ZZone abbreviationUTC
yyyy-MM-dd'T'HH:mm:ssXJava pattern2025-11-16T14:00:00Z