ISO-8601 Duration Converter

Parse and convert ISO-8601 duration strings like P1Y2M3DT4H

Parse an ISO-8601 duration string such as P1Y2M10DT2H30M into total seconds, minutes, hours, and days, plus a plain-English breakdown of every component, using Gregorian averages for years and months. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What format is an ISO-8601 duration?

It starts with P, then optional date parts nYnMnWnD, then a T separator before optional time parts nHnMnS. For example P1Y2M10DT2H30M means 1 year, 2 months, 10 days, 2 hours, and 30 minutes.

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

StringMeaningApproximate total
PT30S30 seconds30 seconds
PT5M30S5 minutes 30 seconds330 seconds
PT2H2 hours7,200 seconds
P1D1 day86,400 seconds
P1W1 week604,800 seconds
P1M1 month (mean)~2,629,746 seconds
P1Y1 year (mean)~31,556,952 seconds
P1Y6M1 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 the duration property (for example PT2H35M for 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() and Period.parse(): Java’s standard library parses these directly; Duration handles the time part (PT...) and Period handles 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 months
  • PT2M = 2 minutes
  • P2MT2M = 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.