Disclosure: Some tools link to SaaS products we may earn a commission from — at no cost to you. All tools are free and run entirely in your browser. See full disclosure →

When You Need ISO 8601 as a Unix Timestamp

REST APIs and databases return dates as ISO 8601 strings. But backend processing — duration calculations, comparisons, expiry logic, scheduling — is far easier with Unix timestamps. If you receive "2024-06-01T00:00:00.000Z" from a Stripe webhook and want to know how many days ago it was, you subtract two integers, not two strings. This converter helps you check the exact integer value of any ISO string, which is useful when debugging API responses, verifying JWT expiry times, and confirming that date arithmetic produces the expected result.

JavaScript Date Parsing Pitfalls

JavaScript's Date parser has known inconsistencies. The safest rule: always include the T separator and a timezone suffix (Z or an offset like +05:30). Without these, date-only strings like "2024-06-01" are parsed as local midnight in some browsers and UTC midnight in others — a bug that is nearly impossible to reproduce across timezones.

The ECMAScript specification changed the behaviour of date-only strings between ES5 and ES2015. As of ES2015, "2024-06-01" is parsed as UTC midnight. But many older environments still use local time. Appending T00:00:00Z is the only reliable cross-browser approach.

// JavaScript — reliable ISO to Unix conversion
Math.floor(new Date('2024-06-01T00:00:00Z').getTime() / 1000)
// → 1717200000

// Python — always specify timezone
from datetime import datetime, timezone
datetime.fromisoformat('2024-06-01T00:00:00+00:00').timestamp()
# → 1717200000.0

// Node.js — using Date.parse
Date.parse('2024-06-01T00:00:00Z') / 1000
// → 1717200000

JWT Expiry and ISO Strings

JSON Web Token (JWT) claims use Unix timestamps for exp and iat. But many token-generation libraries accept ISO strings as input and convert internally. When debugging "token expired" errors, convert the exp timestamp to ISO to compare it against the current time visually. Use the timestamp to date converter for this direction.

Millisecond vs Second Precision

ISO 8601 strings can include sub-second precision: 2024-06-01T00:00:00.123Z. The .123 represents 123 milliseconds. When converting to a Unix timestamp in seconds, this fractional part is truncated (Math.floor). If you need millisecond precision, use the raw millisecond value (Date.getTime()) rather than dividing by 1000.

Frequently Asked Questions

How do I convert an ISO 8601 string to a Unix timestamp in JavaScript?

Use Math.floor(new Date('2024-06-01T00:00:00Z').getTime() / 1000). The Date constructor parses the ISO string, .getTime() returns milliseconds, dividing by 1000 converts to seconds, and Math.floor drops the fractional part. Always include the Z suffix for reliable UTC parsing.

Why does my ISO string parse differently in different timezones?

Date-only ISO strings like '2024-06-01' are timezone-ambiguous. The ECMAScript spec says to parse them as UTC in modern browsers, but older environments use local time. The fix: always include a time and timezone: '2024-06-01T00:00:00Z'. The Z suffix forces UTC parsing in all environments.

What is Date.parse() and how is it different from new Date()?

Date.parse('2024-06-01T00:00:00Z') returns milliseconds since epoch (same as new Date('2024-06-01T00:00:00Z').getTime()). The difference is that new Date() creates a Date object which has formatting methods, while Date.parse() returns a plain number. For just getting the timestamp, Date.parse() is slightly faster — but new Date().getTime() is more readable.

What timezone does an ISO string use if there is no Z or offset?

According to the ES2015 spec, date-time strings without a timezone (e.g. '2024-06-01T12:00:00') are treated as local time. This behaviour changed from ES5, which treated them as UTC. To be safe, always include Z or an explicit offset. Never pass timezone-ambiguous strings to Date() in production code.

How does Python convert ISO 8601 to Unix timestamp?

Use datetime.fromisoformat('2024-06-01T00:00:00+00:00').timestamp(). In Python 3.11+, fromisoformat() also accepts Z as a timezone: datetime.fromisoformat('2024-06-01T00:00:00Z'). In older Python 3, replace Z with +00:00 before parsing. Always cast to int() to get a clean integer timestamp.

Number & Date Converters
Hex to Decimal Decimal to Hex Binary to Decimal Decimal to Binary RGB to Hex Hex to RGB Timestamp to Date Date to Timestamp Unix to ISO 8601
💡
Need AI tools for your development workflow?

Explore our reviews of the best AI coding assistants, documentation generators, and developer productivity tools — ranked by real-world usefulness.

Browse AI Tools for Developers →
The DevTools Team
Infinfy Engineering
We build free developer utilities that we actually use ourselves. No accounts, no tracking, no backend — just fast, accurate, in-browser tools. Part of Infinfy Solutions.