ISO 8601 Duration Converter

Enter an ISO 8601 duration to parse, or total seconds to format.

How it is calculated

The tool works in two directions. Parse reads a string of the form PnYnMnDTnHnMnS or PnW, the format with designators of ISO 8601 (4.4.3.2; XML Schema's xs:duration is the same form without weeks and with a fraction on the seconds only): each part is optional but at least one must be present, the parts keep that order, the T separates the date part from the time part, and a week count stands on its own. The last part may have a decimal fraction written with a full stop or a comma. Total seconds are weeks × 604800 + days × 86400 + hours × 3600 + minutes × 60 + seconds, so a day is always exactly 86,400 seconds. Years and months are not converted, since a month can be 28 to 31 days: they are listed next to the seconds and in their own line. The breakdown carries each unit over to the next and leaves out zero parts, so PT36H reads 1d 12h and PT0,5H 30m. Format takes a number of seconds, drops any fraction, and splits it into days, hours, minutes and seconds to build the string; zero gives PT0S. A fraction on any part but the last, weeks mixed with other parts (P1W2D), a T with nothing after it, minus signs and lowercase letters give no result.

Worked example

Parse the duration P1DT2H30M. The P opens the period, 1D is one day, the T switches to time, 2H is two hours and 30M is thirty minutes. Seconds: 1 × 86400 = 86,400, plus 2 × 3600 = 7,200, plus 30 × 60 = 1,800, which totals 95,400 s. The tool shows the readable form 1d 2h 30m. Going the other way, 95400 seconds in format mode returns P1DT2H30M.

Try this example →

Common mistakes

  • Leaving out the T before the hours, so P2H is rejected. Hours, minutes and seconds all need the T in front of them.
  • Confusing the two Ms: before the T it means months (P3M), after it minutes (PT3M).
  • Expecting months or years in the total seconds. They have no fixed length, so the tool lists them apart; add them yourself with the calendar dates in mind.
  • Putting a fraction on an earlier part, as in PT1.5H30M. Only the last part may have one; write PT2H or PT1H60M style values instead.
  • Combining weeks with days, as in P1W2D. Write it as P9D.

Sources

About this calculator

ISO 8601 is the international standard for writing dates, times, and durations so that computers everywhere parse them the same way. Its duration format packs years, months, weeks, days, hours, minutes, and seconds into one string that opens with P (for “period”) and inserts a T before any time-of-day components — so P1DT2H30M reads as 1 day, 2 hours, 30 minutes, with no locale-dependent word order to trip up a parser.

This exact notation is what XML Schema's xs:duration type stores, what iCalendar (RFC 5545) uses for event durations, and what REST APIs from AWS, Google Calendar, and Stripe return for elapsed-time fields; language libraries like Java's Duration/Period classes and Python's isodate module read and write it natively. The parser follows the format with designators of ISO 8601 (section 4.4.3.2 of the ISO 8601-1 draft): years (Y), months (M before the T), weeks (W, on their own), days (D), hours (H), minutes (M after the T) and seconds (S), and the last component may have a decimal fraction written with a comma or a full stop, such as PT1.5S or PT0,5H (XML Schema's xs:duration has the same form without weeks and allows a fraction, with a full stop, on the seconds only). Weeks, days, hours, minutes and seconds are added up exactly (a day as 86,400 seconds, a week as 7 days); years and months are shown separately, because their length in seconds depends on the calendar dates they fall on. Formatting goes the other way, turning whole seconds into a P…D T…H…M…S string, with a human-readable breakdown.

Was this helpful?

You can pick up to 3 reactions.

Note from the editors

Weeks, days, hours, minutes and seconds are added up as pure clock time here, a day always being 86,400 seconds, which is why P1D is not quite the same thing as a calendar day across a daylight-saving change. Years and months are listed apart, since their length depends on the dates: P1Y2M10D gives 864,000 s plus 1 year 2 months. Note that 129600 seconds formats as P1DT12H, while PT36H parses to 129,600 s as well. Which API gave you a duration string you could not read at first?

Comments

  • Be the first to comment.

Popular calculators

All Calculators