Tutorials
Convert ISO 8601 to Unix Timestamp
Convert an ISO 8601 Timestamp to Unix Seconds
An ISO 8601 value becomes an unambiguous Unix timestamp only when it includes
Z for UTC or a numeric UTC offset. For example,
2024-01-01T00:00:00Z is Unix timestamp 1704067200 in seconds.
Use the ISO 8601 Converter to convert a value without writing code. This tutorial shows the same conversion in JavaScript and Python, including the milliseconds-versus-seconds distinction.
JavaScript: ISO 8601 to Unix Timestamp
JavaScript parses a complete ISO 8601 value into a Date. getTime() returns
milliseconds, so divide by 1000 only when the receiving API expects Unix
seconds.
const input = '2024-01-01T00:00:00Z';
const date = new Date(input);
if (Number.isNaN(date.getTime())) {
throw new Error('Invalid ISO 8601 timestamp');
}
const milliseconds = date.getTime();
const seconds = Math.floor(milliseconds / 1000);
console.log(milliseconds); // 1704067200000
console.log(seconds); // 1704067200
The offset describes the instant, not just formatting. These inputs represent the same instant and produce the same result:
const utc = new Date('2024-01-01T00:00:00Z').getTime();
const offset = new Date('2024-01-01T05:30:00+05:30').getTime();
console.log(utc === offset); // true
For a focused JavaScript round trip, see convert timestamps in JavaScript.
Python: ISO 8601 to Unix Timestamp
Python's datetime.fromisoformat() retains a numeric offset. Normalize to UTC
when you need a canonical representation.
from datetime import datetime, timezone
value = "2024-01-01T05:30:00+05:30"
instant = datetime.fromisoformat(value).astimezone(timezone.utc)
assert instant.isoformat() == "2024-01-01T00:00:00+00:00"
assert int(instant.timestamp()) == 1_704_067_200
What About a Value Without a Timezone?
2024-01-01T00:00:00 contains a date and time but no offset. Different
machines can interpret it differently, so it has no single correct Unix
timestamp. Decide whether the source is UTC or a named local timezone, then
attach that policy before conversion. The ISO 8601 format guide
explains Z, offsets, and local date-times in more detail.
Verify the Result
Use the Unix Timestamp Converter to verify the seconds result, and use the timestamp to ISO guide when you need to convert in the other direction. For validation rules that are stricter than general ISO 8601 parsing, compare RFC 3339 and ISO 8601.
Try It Yourself
Test Your Timestamp Conversion
Need more options? ISO 8601 Converter