apprun.icuGuides

Guide · Developer tools

Unix timestamps: seconds, milliseconds and timezone mistakes

A Unix timestamp describes an instant relative to the epoch. Seconds and milliseconds differ by 1,000. Select the unit explicitly, then use an ISO datetime with Z or an offset when converting back.

By apprun.icuUpdated Read 4 minIncludes a working browser tool
On this page
  1. The short answer
  2. Write the unit next to the number
  3. Separate the instant from its display
  4. Use explicit ISO input
  5. Handle precision and rounding
  6. Know what a timestamp cannot express
  7. Test the pipeline at its boundaries
  8. Common questions
  9. Sources and further reading
1,000 milliseconds → ÷ 1,000 → 1 Unix second1,000 milliseconds÷ 1,0001 Unix second
1,000 milliseconds → ÷ 1,000 → 1 Unix second. Follow the units and the representation at each step.

Write the unit next to the number

A timestamp without a unit is an incomplete contract. Many Unix-oriented APIs use seconds, while JavaScript Date values commonly use milliseconds. Passing a seconds value directly to a millisecond API can move a modern date close to 1970.

Do not rely only on digit count. Contemporary positive values often have recognizable lengths, but historical dates, negative timestamps, test fixtures and future values break that shortcut. Name fields unixSeconds or unixMilliseconds in your own code and documentation. A deliberate field name is cheaper than debugging a silent unit conversion.

Separate the instant from its display

One instant can be displayed as noon in one timezone and mid-afternoon in another. The timestamp does not acquire a different value because the viewer is in another city. A timezone changes the calendar representation, not the underlying instant.

The converter shows UTC and your browser’s local display side by side. Use the UTC output for comparing logs across machines, and the local display for checking what a person sees. If a server writes a local datetime without a timezone, the reader cannot reliably reconstruct the original instant from that text alone.

Try it with your own input

Your result

Use explicit ISO input

A reliable date-to-timestamp input includes a date, a time and either Z for UTC or a numeric offset such as +03:00. For example, 2026-10-11T12:00:00Z and 2026-10-11T15:00:00+03:00 represent the same instant.

This tool rejects a timezone-free datetime and a bare calendar date. That avoids depending on browser-specific parsing or on the timezone of the machine performing the conversion. It also checks calendar values so that an impossible date is not quietly normalized into another month.

Handle precision and rounding

Whole Unix seconds cannot retain arbitrary millisecond precision. Converting a datetime with fractional seconds to a whole-second timestamp discards part of the instant; choose a rounding policy that matches your application. This tool uses floor for its Unix-seconds result.

For a time before the epoch, floor moves toward the earlier second rather than toward zero. Keep that behavior in mind when testing negative values. Very large integers also require attention to numeric precision and the supported date range. A value can look like an integer in a text file while being unsafe to represent exactly as a JavaScript Number.

Know what a timestamp cannot express

A birthday, a recurring 09:00 appointment and an exact instant are different data types. A birthday may need only a calendar date. A recurring meeting usually needs a timezone rule as well as a local time so it can follow daylight-saving transitions.

Unix time also does not represent leap seconds as distinct extra seconds. If your application needs specialized timekeeping or historical timezone interpretation, use the appropriate data model and library. A quick converter is useful for logs and integration checks; it does not replace a calendar system.

Test the pipeline at its boundaries

Check a known epoch value, one modern instant, a negative value and a datetime with an explicit nonzero offset. Compare the result with the API’s documented unit. When exporting through CSV, preserve the timestamp field as a string until the schema makes its unit clear.

The CSV guide explains why automatic number and date inference can damage identifiers. If the timestamp is placed in a URL, use the URL component tool for the value boundary. Keep time conversion, data typing and transport encoding as separate steps.

Common questions

Why did my timestamp turn into a date in 1970?

A common cause is interpreting Unix seconds as milliseconds. Confirm the API’s unit before multiplying or dividing.

Does changing timezone change the timestamp?

No. It changes the displayed calendar time for the same instant.

Can I enter a date without a timezone?

This tool requires Z or an explicit offset to avoid an ambiguous conversion.

Does Unix time include leap seconds?

Ordinary Unix timestamps do not represent leap seconds as distinct extra seconds.

What happens to fractional seconds?

The millisecond result retains supported fractional precision; the whole-second output uses floor.

Sources and further reading

Share this guide