ISO 8601 Duration Converter
Enter an ISO 8601 duration to parse, or total seconds to format.
Result
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.
Common mistakes
- Leaving out the
Tbefore the hours, soP2His 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; writePT2HorPT1H60Mstyle values instead. - Combining weeks with days, as in
P1W2D. Write it asP9D.
Sources
- ISO/WD 8601-1 (2016), Representation of dates and times, Part 1: Basic rules, 4.4.3.2 Format with designators (working draft) — ISO/TC 154/WG 5 N0038, hosted by the Library of Congress
- W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes, 3.3.6 duration — W3C Recommendation, 2012
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.
Comments
- Be the first to comment.
Popular calculators
Loan Calculator
Monthly payment, total interest and full amortization schedule.
Percentage Calculator
Percent change, percent of, and ratio calculations.
Discount Calculator
Calculate final price, savings, and discount amount.
BMI Calculator
Body mass index from height and weight (metric or imperial).
Age Calculator
Compute your exact age in years, months and days from a birth date.
Compound Interest Calculator
Calculate the final amount and interest earned with compounding.
All Calculators
- Loan Calculator
- Profit Calculator
- Discount Calculator
- BMI Calculator
- Percentage Calculator
- Ideal Weight Calculator
- Age Calculator
- Pregnancy Due Date Calculator
- Compound Interest Calculator
- BMR Calculator (Basal Metabolic Rate)
- Tip Calculator
- Fuel Cost Calculator
- Date Difference Calculator
- Sleep Cycle Calculator
- Daily Water Intake Calculator
- Simple Interest Calculator
- Heart Rate Zones Calculator
- Running Pace Calculator
- Pet Age Calculator
- Calories Burned Calculator
- Macro Calculator
- TDEE Calculator (Total Daily Energy Expenditure)
- Waist-to-Hip Ratio Calculator
- Honor Roll Calculator
- One Rep Max (1RM) Calculator
- Ovulation Calculator
- Electricity Cost Calculator
- Unit Price Calculator
- Savings Goal Calculator
- Break-Even Point Calculator
- Paint Calculator
- Course Grade Average Calculator
- Business Days Calculator
- Time Duration Calculator
- Fuel Economy Calculator
- Temperature Converter
- Tile Calculator
- Aspect Ratio Calculator
- Roman Numeral Converter
- Goal Weight Timeline Calculator
- Salary Converter (Hourly to Annual)
- Credit Card Validator (Luhn)
- Body Surface Area (BSA) Calculator
- Feels-Like Temperature Calculator
- Ohm's Law Calculator
- PPI (Pixel Density) Calculator
- Molar Mass Calculator
- Zodiac Sign Calculator (Western + Chinese)
- IBAN Validator
- Shoe Size Converter
- Country Info & Dialing Code Lookup
- Time Zone Difference (World Clock)
- CAGR (Compound Annual Growth Rate) Calculator
- Rule of 72 Calculator
- Blood Alcohol Content (BAC) Calculator
- Lean Body Mass (LBM) Calculator
- Pythagorean Theorem Calculator
- Speed Converter
- Download Time Calculator
- Date Calculator (Add/Subtract)
No calculators found
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?