Convert Unix Timestamps in JavaScript, Python, and Excel
Convert epoch seconds and milliseconds to dates, display UTC and US time zones, and avoid spreadsheet and daylight saving time mistakes.
Identify seconds or milliseconds first
The values 1704067200 seconds and 1704067200000 milliseconds represent the same instant: January 1, 2024 at 00:00:00 UTC. For contemporary dates, ten digits often suggest seconds and thirteen often suggest milliseconds. Digit count is only a clue, not a reliable format definition.
Check the API documentation or field name. Very old dates, negative values, and microsecond timestamps break digit-count shortcuts. An unexpected date in January 1970 often means seconds were interpreted as milliseconds.
| Value | Unit | UTC result |
|---|---|---|
| 0 | seconds | 1970-01-01 00:00:00 |
| 1704067200 | seconds | 2024-01-01 00:00:00 |
| 1704067200000 | milliseconds | 2024-01-01 00:00:00 |
Convert epoch time in JavaScript
Use toISOString for a UTC result with an explicit Z suffix. When going from a date string to epoch seconds, include a timezone offset or Z so the input has an unambiguous meaning.
For a visitor-facing display, format the same instant with Intl.DateTimeFormat. Use a named region such as America/New_York rather than subtracting a fixed number of hours; the region’s UTC offset can change with daylight saving time.
const seconds = 1704067200;
const date = new Date(seconds * 1000);
console.log(date.toISOString()); // 2024-01-01T00:00:00.000Z
console.log(new Intl.DateTimeFormat("en-US", {
timeZone: "America/New_York",
dateStyle: "medium", timeStyle: "short"
}).format(date)); // Dec 31, 2023, 7:00 PM
const backToSeconds = Math.floor(
Date.parse("2024-01-01T00:00:00Z") / 1000
);
console.log(backToSeconds); // 1704067200Convert with an explicit UTC timezone in Python
Pass timezone.utc to create a timezone-aware datetime. Without an explicit timezone, fromtimestamp uses the machine’s local timezone, so the displayed result may differ between a laptop and a server.
For a millisecond input, divide by 1,000 before calling fromtimestamp. Keep the original integer if your application must preserve exact subsecond values through later calculations.
from datetime import datetime, timezone
seconds = 1704067200
date = datetime.fromtimestamp(seconds, tz=timezone.utc)
print(date.isoformat()) # 2024-01-01T00:00:00+00:00
print(int(date.timestamp())) # 1704067200Convert a timestamp in Excel or Google Sheets
If A2 contains epoch seconds, divide by 86,400 to convert seconds to days and add the epoch date. For milliseconds, divide by 86,400,000 instead. Format the result cell as a date and time; otherwise the spreadsheet shows a serial number.
These formulas calculate a UTC date and time and do not apply named timezone or daylight saving rules. Label the column UTC to prevent readers from mistaking it for their local time. Some spreadsheet locales use semicolons instead of commas in function arguments.
=DATE(1970,1,1)+A2/86400
=DATE(1970,1,1)+A2/86400000
Example display format: yyyy-mm-dd hh:mm:ssAvoid ambiguous dates across countries
The text 03/04/2026 can mean March 4 or April 3. Exchange timestamps as a documented numeric unit or use an ISO 8601 timestamp with an offset. Keep localized formatting for the display layer.
A time such as 1:30 AM can occur twice on the day some regions leave daylight saving time. A date without an offset cannot distinguish those instants. Store the instant and, where relevant, the intended named timezone separately. For future appointments, keep the scheduling rules too rather than assuming today’s offset will always apply.
Frequently asked questions
Is a Unix timestamp different in the USA and Europe?
The same timestamp identifies the same instant everywhere. The displayed calendar date and time depend on the timezone and formatting locale.
Why is my converted date in 1970?
A common cause is passing epoch seconds directly to a function that expects milliseconds. Confirm the source unit before multiplying; missing or zero values can also produce an epoch-era date.
References
Check the official documentation for command options and runtime-specific behavior.
Integrated Tools & Learning Resources
DevX Tool combines deep engineering tutorials with client-side interactive tooling so you can test code, verify outputs, and troubleshoot bugs right away.
Related tutorials and articles
Unix Timestamps: Seconds vs Milliseconds vs Microseconds
The 10-Digit vs 13-Digit Disaster: Debugging Unix Epoch Millisecond and Microsecond Serialization Across Distributed APIs
Read article Distributed SystemsThe Year 2038 Problem: Unix Timestamp Overflow
The Year 2038 Problem (Y2038): Surviving the 32-Bit Signed Integer Unix Epoch Rollover in Legacy Systems
Read article Web troubleshootingHTTP Error Codes: 400, 401, 403, 404, 429 & 500
Find what common HTTP errors mean, what to check in an API response, and when a retry can help. Includes a status-code comparison and debugging steps.
Read article Developer fundamentalsJSON vs YAML vs TOML: Which Configuration Format Fits?
Compare JSON, YAML, and TOML using the same configuration example. Understand comments, indentation, data types, and safe conversion between formats.
Read article