What an ISO-8601 duration looks like
ISO-8601 represents a span of time as a string that begins with P for period.
Date components come first as nY years, nM months, nW weeks, and nD days,
followed by a T and the time components nH hours, nM minutes, and nS
seconds. The same letter M means months before the T and minutes after it,
which is the most common point of confusion. This tool parses the whole string
and reports both totals and a per-component breakdown.
How it works
The parser matches the canonical grammar with a single regular expression,
extracting each optional component and rejecting strings that do not fit, such as
a trailing T with no time parts. It accepts decimal fractions written with a
dot or a comma, so PT1,5H and PT1.5H are equivalent.
To compute a single total, the components are summed into seconds. Days, hours, minutes, and seconds are exact. Years and months have no fixed length, so the tool uses Gregorian mean values: a year is 365.2425 days and a month is one twelfth of a year. Weeks are exactly 7 days.
P1Y2M10DT2H30M -> about 37,090,800 seconds
PT45M -> 2,700 seconds
P2W -> 1,209,600 seconds
P0Y0M0DT0H0M30S -> exactly 30 seconds
Quick format reference
| String | Meaning | Approximate total |
|---|---|---|
PT30S | 30 seconds | 30 seconds |
PT5M30S | 5 minutes 30 seconds | 330 seconds |
PT2H | 2 hours | 7,200 seconds |
P1D | 1 day | 86,400 seconds |
P1W | 1 week | 604,800 seconds |
P1M | 1 month (mean) | ~2,629,746 seconds |
P1Y | 1 year (mean) | ~31,556,952 seconds |
P1Y6M | 1 year, 6 months | ~47,335,428 seconds |
Where ISO-8601 duration strings appear
Duration strings in this format appear in several real-world systems:
- HTML
<video>and<audio>metadata: some schema.org markup uses ISO-8601 duration in thedurationproperty (for examplePT2H35Mfor a 2 hour 35 minute film). - RSS and Atom feeds: podcast feed duration fields often use ISO-8601.
- OpenAPI / JSON Schema:
"format": "duration"in a JSON Schema definition expects an ISO-8601 duration string. - Calendar and scheduling APIs: Google Calendar’s API uses ISO-8601 durations for event lengths and repeat intervals.
- Jenkins, GitHub Actions, and CI tools: build timeout configurations often accept duration strings.
- Java
Duration.parse()andPeriod.parse(): Java’s standard library parses these directly;Durationhandles the time part (PT...) andPeriodhandles the date part (P...).
The M ambiguity and how to avoid it
The most common source of confusion is the letter M, which means months in the date section and minutes in the time section. The T separator is essential:
P2M= 2 monthsPT2M= 2 minutesP2MT2M= 2 months and 2 minutes (unusual but valid)
If you see a duration string that appears to mean minutes but has no T, the parser will correctly interpret it as months. Always check the component breakdown this tool produces to confirm the parse was what you expected.
Notes
Use the component breakdown to verify intent before relying on the totals. If your duration contains only days and smaller units the totals are exact to the second. If it contains years or months, treat the seconds total as a mean. For exact calendar arithmetic, add the duration to a specific start date rather than converting it to a fixed number of seconds.