ISO 8601 Duration Parser
Parse P1Y2M3DT4H5M6S durations into total seconds, days, and human prose.
The ISO 8601 duration grammar
An ISO 8601 duration is P[date-part]T[time-part]: a literal P (for "period"), zero or more date components (years Y, months M, weeks W, days D), an optional T separator, and zero or more time components (hours H, minutes M, seconds S). The canonical example P1Y2M3DT4H5M6S means "1 year, 2 months, 3 days, 4 hours, 5 minutes, 6 seconds".
The format has four common gotchas that this parser handles explicitly:
1. The M ambiguity. Before the T, M means months; after T, it means minutes. P1M is one month; PT1M is one minute; P1MT1M is one month and one minute. Forget the T and your durations shift by orders of magnitude.
2. Weeks don't mix. P1W means exactly one week (7 days), but a strict ISO 8601 parser won't let you combine W with other date parts — P1W2D is not canonical. Most modern implementations accept mixed week-plus-day forms as an extension, and this tool will parse them while flagging that the canonical form is weeks-only or weeks-converted-to-days.
3. Years and months are calendar-relative. P1Y between 2023-03-14 and 2024-03-14 is exactly one year, but "1 year in seconds" depends on whether you cross a leap day. This tool reports total seconds using the nominal values (Y=31,536,000s, M=2,592,000s = 30 days) for quick math, and you should anchor to a concrete start date if you need calendar-accurate arithmetic. For precise calendar math, use a duration library like Temporal or date-fns.
4. Fractional components are allowed on the smallest unit. PT0.5S is half a second; PT1.5M is 90 seconds. Only the smallest-present unit may carry a decimal — P1.5Y is technically invalid under strict ISO 8601, though permissive parsers accept it.
Paste a duration below to see its canonical form, human-readable prose, total seconds, and a breakdown of every component.
Frequently asked questions
Why does 'PT1M' mean one minute but 'P1M' mean one month?
The "M" letter is reused — it means months when it appears in the date part (before the T separator) and minutes when it appears in the time part (after T). This is the most common ISO 8601 footgun: omit the T and your duration shifts from minutes to months, silently skewing data by a factor of 43,200. Always write the T even if the date part is empty — prefer "PT30M" over "P30M" when you mean thirty minutes. Most schedulers, backup tools, and REST APIs will reject a missing T outright; permissive parsers may accept it with an interpretation you didn't intend.
Can I combine weeks with other date parts like P1W2D?
Strictly, no — ISO 8601 treats the week designator as mutually exclusive with the other date parts. "P1W" is canonical for 7 days; combining week with days, months, or years produces a non-canonical string. In practice most modern parsers (including this one) will accept "P1W2D" and convert to 9 days, but round-tripping through a strict tool may reject it. If you need portability, convert weeks to days before serialising: write "P9D" instead of "P1W2D".
How does total-seconds math work for years and months?
This parser reports total seconds using nominal unit values — a year is exactly 365 days (31,536,000 s), a month is exactly 30 days (2,592,000 s). That's handy for sorting, rough rate-of-change calculations, and cache TTLs, but it's wrong by up to 28 hours when a concrete start date crosses a leap day, or by up to a day when a month spans February or a 31-day month. If you need calendar-accurate arithmetic, anchor the duration to a concrete start date and use the Temporal proposal or a library like date-fns/luxon to do the addition — ISO 8601 duration math is deliberately ambiguous without an anchor.
Other ISO 8601 Parser cases
ISO 8601 Week Date Parser
Parse YYYY-Www-D week dates into a calendar date and day-of-week.
ISO 8601 Ordinal Date Parser
Convert YYYY-DDD ordinal (day-of-year) dates to calendar dates.
ISO 8601 Interval Parser
Parse start/end, start/duration, and duration/end intervals including repeats.
All of ISO 8601 Parser
Parse any form — auto-detected.
This is a variant landing page for ISO 8601 Parser. Every transform runs in your browser — nothing you paste is sent to our server or any third party.