Unix seconds vs milliseconds: fix dates and time zones
An API returns a number that becomes a date in 1970, or appears eight hours away from a log entry. Check the unit and time zone separately before changing the formula. A fixed eight-hour adjustment can hide the real cause.
Open tool: Unix timestamp1. Start with one known instant
Enter the following values one at a time in the timestamp tool, selecting Seconds or Milliseconds for numeric input. They should produce the same UTC result. Date strings need an explicit time zone.
Seconds: 1788768000
Milliseconds: 1788768000000
UTC: 2026-09-07T08:00:00.000Z
UTC+08:00: 2026-09-07T16:00:00+08:002. Choose the unit from the API contract
Recent timestamps are often 10-digit seconds or 13-digit milliseconds, but length is only a clue. Values near 1970 or in distant dates do not follow that pattern. Check the field documentation, type or name, such as createdAtMs.
JavaScript Date interprets numeric input as milliseconds. Multiply seconds by 1000 before constructing a Date. Flooring milliseconds to whole seconds discards the millisecond fraction; keep milliseconds when that precision matters.
const seconds = 1788768000;
const milliseconds = seconds * 1000;
console.log(new Date(milliseconds).toISOString());
// 2026-09-07T08:00:00.000Z
console.log(Math.floor(milliseconds / 1000));
// 17887680003. Check seconds-as-milliseconds when you see 1970
new Date(1788768000) produces 1970-01-21T16:52:48.000Z: that many milliseconds is only a short interval after the epoch. If the field is defined in seconds, use new Date(1788768000 * 1000).
On this site, convert 1788768000 with Seconds selected, then 1788768000000 with Milliseconds selected. The UTC outputs should match. If only one call path is wrong, check for a missing or repeated multiplication by 1000.
4. Separate the instant from its local display
2026-09-07T08:00:00Z and 2026-09-07T16:00:00+08:00 identify the same instant. Z denotes UTC; +08:00 means the written local time is eight hours ahead. Do not add that offset to the timestamp again.
Use the UTC field for comparisons across devices; Local time follows the device time zone. Date text must include Z or an explicit offset. For a scheduled job in a named time zone, choose the zone in the Cron tool instead of manually shifting timestamps.
5. Verify with a round trip
Copy the UTC result back into the converter and check that Unix (ms) is unchanged. Also try 0 and -1 seconds to check the epoch and negative values. If your application needs millisecond precision, compare Unix (ms), not only the floored seconds field.
- Confirm the unit from the API definition.
- Confirm that date text includes the intended time zone.
- Confirm that scaling by 1000 occurs only at the required boundary.
- Compare UTC and the original milliseconds to avoid confusing display differences with data errors.