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 P[n]D T[n]H[n]M[n]S (without the spaces), where each part is optional but at least one must be present, and the T separates days from the time part. Total seconds are days × 86400 + hours × 3600 + minutes × 60 + seconds. 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. Only whole numbers of D, H, M and S are accepted. Years, months, weeks (P1W), decimals (PT1.5S) and lowercase letters give no result. A day is always exactly 86,400 seconds.

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.
  • Writing weeks or months, such as P2W or P3M. This tool only knows days, hours, minutes and seconds, so convert weeks to days first.
  • Using a decimal such as PT0.5H or PT1.5S. Only whole numbers are read, so write PT30M instead.
  • Confusing M: after the T it means minutes. A month cannot be written here at all.

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. Converting a duration string to total seconds means summing each designator’s value times its unit (days×86400, hours×3600, minutes×60, seconds×1); going the other way means peeling seconds off in the same order and re-assembling the P/T string — which is exactly what this converter automates, along with a human-readable breakdown. It works with days, hours, minutes, and whole seconds only: durations containing years, months, weeks (such as P1W or P1Y2M), or fractional seconds are not accepted, so convert those to days first.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    Durations here are pure clock time, a day always being 86,400 seconds, which is why weeks, months and years are refused: their length varies. That also means P1D is not the same thing as 24 hours in a calendar across a daylight-saving change. 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?

Popular calculators

All Calculators