Back to all patterns
ISO 8601 Duration
Dates & Numbers
Matches an ISO 8601 duration (PT1H30M, P3D, P1Y2M3DT4H5M6S).
/^P(?!$)(?:[0-9]+Y)?(?:[0-9]+M)?(?:[0-9]+W)?(?:[0-9]+D)?(?:T(?:[0-9]+H)?(?:[0-9]+M)?(?:[0-9]+(?:\.[0-9]+)?S)?)?$/How it works
Durations start with P, optional date components (Y/M/W/D), optional T separator, then time components (H/M/S). At least one component must follow P. Used by Kubernetes, ActivityStreams, and the JS Temporal API.
Test Cases
Should Match
- PT1H30M
- P3D
- P1Y2M3DT4H5M6S
- PT0S
Should NOT Match
- P
- 1H
- PT
Quick Summary
Matches ISO 8601 duration strings (P[date]T[time]).