ISO 8601 Duration Converter

Parse ISO 8601 duration strings like PT1H30M or P1Y2M3DT4H5M6S into human-readable time. Also build ISO durations from seconds, hours, or component values.

Format: P[n]Y[n]M[n]DT[n]H[n]M[n]S — P is required, T separates date from time components

Common Examples — click to try

What Is ISO 8601 Duration?

ISO 8601 is the international standard for representing dates and times. Its duration format uses a compact string that encodes years, months, days, hours, minutes, and seconds. The format begins with P (for Period), optionally has date components (Y, M, D), then a T separator before time components (H, M, S). Examples: PT30S (30 seconds), PT1H30M (1 hour 30 minutes), P1Y6M (1 year 6 months), P1Y2M3DT4H5M6S (full specification).

Where Is ISO Duration Used?

ISO 8601 durations appear everywhere in modern software: REST APIs (YouTube video duration, Spotify track length), Kubernetes (pod timeout and retry intervals), AWS (Lambda timeout, SQS visibility timeout in CloudFormation), HTML5 media (the <video> element's duration attribute), JavaScript (Temporal API, Luxon, date-fns), Java (java.time.Duration, java.time.Period), Python (isodate library), PostgreSQL (INTERVAL type).

The T separator is critical. P1M = 1 Month (date component). PT1M = 1 Minute (time component). Without T, M means months. After T, M means minutes. This is a common source of bugs when parsing durations manually.
Native JavaScript doesn't have built-in ISO duration parsing. Use the Temporal API (Stage 3 proposal): Temporal.Duration.from('PT1H30M'). Or use the Luxon library: Duration.fromISO('PT1H30M'). Or use a regex: /^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$/.
The standard allows fractional values in the lowest-order component only. So PT1.5M (1.5 minutes = 90 seconds) is valid, but P1.5Y2M is not. In practice, most libraries only accept integer values for all components.