ISO 8601 Duration Calculator

Read PT1H30M or P3Y6M4DT12H30M5S, convert to seconds, add to a date with correct month-end rules, find the calendar difference of two dates and sum a list.

ทำงานในเบราว์เซอร์ของคุณ ไฟล์ไม่ออกจากอุปกรณ์ ดูวิธีตรวจสอบ

…

วิธีทำ

  1. 1
    Enter a duration

    Type or paste a string, or set the fields for years to seconds.

  2. 2
    Read the results

    Check the canonical form, words, normalised form and totals.

  3. 3
    Add to a date

    In the add tab pick the start, choose add or subtract and a repeat count.

  4. 4
    Find a difference

    In the between tab enter two date-times and use the result.

  5. 5
    Process a list

    Paste one duration per line in the batch tab and read the sum.

  6. 6
    Export

    Copy the duration or download the series and batch tables as CSV.

เกี่ยวกับเครื่องมือนี้

ISO 8601 writes a length of time as a compact string: P starts the duration, then years, months, weeks and days, then T and hours, minutes and seconds. PT45M is 45 minutes, P1D is one day and P1Y2M10DT2H30M is one year, two months, ten days, two hours and thirty minutes. The format turns up in YouTube and schema.org metadata, XML Schema xs:duration, Java, .NET and Python libraries, cloud scheduling APIs, iCalendar and HL7 messages. It is easy to read once you know it, and easy to get wrong when you write it by hand: PT1M is one minute but P1M is one month. This calculator parses and validates durations, builds them from fields, shows the canonical and normalised forms with a plain-English reading and total seconds, adds a duration to a date or repeats it as a series, finds the calendar duration between two date-times, and sums a whole list.

The grammar

A duration starts with P, optionally after a minus sign. Date parts follow in the order Y, M, W, D; then a T separates time parts H, M and S. Every part is optional, but at least one must be present, and a T must be followed by a time part. Only the smallest unit may have a decimal fraction, written with a point or comma, so PT0.5S and PT1.5H are valid but PT1.5H30M is not. The alternative format P0001-02-10T02:30:00 is also accepted and converted. Weeks combined with other units are allowed by the 2019 edition of ISO 8601 but rejected by some older parsers, and the tool warns you.

Nominal and exact lengths

Hours, minutes and seconds have fixed lengths, and in UTC so do days and weeks. Years and months do not: February has 28 or 29 days and a year has 365 or 366. When a duration contains years or months, the seconds total uses the average Gregorian year of 365.2425 days and month of 30.436875 days, which is what many libraries do, and the page marks the value as nominal. For an exact answer, add the duration to a real date.

Adding to a date

The add tab applies years and months first and keeps the day of the month, clipping to the last day when the target month is shorter: 31 January plus P1M is 28 February in 2026. Then weeks and days are added, then the time part. Subtracting goes the other way. The repeat field builds a series by adding the duration to each previous result, the way iCalendar recurrence works, and exports it as CSV.

Between two dates

The difference tab counts whole months from the start date first, then the leftover days and time, so start plus the result always lands exactly on the end date; the check line proves it. Totals in days, hours and seconds are shown too.

Normalising and batch

Normalising carries 90 minutes into PT1H30M and, if you ask, 36 hours into P1DT12H. Months are carried into years only when they are whole. The batch tab reads one duration per line, flags invalid lines, converts each one and sums them.

Limits

Date-times are treated as UTC, so daylight-saving changes in a local zone are not applied: adding P1D across a clock change gives 24 hours, which a local-time calendar might show as 23 or 25. Leap seconds are ignored, as in almost all software. Durations in other notations, such as 1h30m or 01:30:00, have to be converted first.

ตัวอย่างพร้อมวิธีทำ

A subscription starts on 31 January 2026 at 09:00 UTC with a term of P1Y2M10DT2H30M. Adding it gives 10 April 2027 at 11:30: one year to 31 January 2027, two months to 31 March, ten days to 10 April and 2.5 hours to 11:30. Its nominal length is 37,689,444 seconds. The difference between 15 January 2026 08:30 and 1 March 2027 17:45 is P1Y1M14DT9H15M, or 410.39 days in total. Summing the batch list PT45M, PT1H30M, P1D, PT90S, P2W, P1M, PT0.5S and -PT15M gives about 45.5 days, marked as nominal because it contains a month.

สรุปสั้น ๆ

คำถามที่พบบ่อย

What is the difference between P1M and PT1M?

P1M is one month and PT1M is one minute. Everything after T is a time unit, so the T matters.

How many seconds is P1M?

There is no single answer. With the average month it is 2,629,746 seconds, but adding P1M to a date moves to the same day next month, which can be 28 to 31 days later.

Is PT36H valid or must it be P1DT12H?

Both are valid ISO 8601. PT36H is exactly 36 hours; P1DT12H is one calendar day plus 12 hours, which differs across a daylight-saving change in local time.

Can a duration be negative?

ISO 8601 itself has no sign, but XML Schema, Java and many libraries accept a leading minus, as in -PT15M. The tool supports it.

Why did 31 January plus one month give 28 February?

There is no 31 February, so the day is clipped to the month end, which is how most date libraries behave.

Does this work for YouTube video lengths?

Yes. YouTube's API returns lengths such as PT1H2M10S; paste them into the batch tab to convert and total them.

ฟรีทั้งหมดไม่มีค่าใช้จ่าย ไม่ต้องสมัคร
ไฟล์เป็นส่วนตัวทุกอย่างทำงานในเบราว์เซอร์ของคุณ
ใช้ง่ายในภาษาของคุณมีหลายภาษา