📅Date & Time
ISO 8601 Duration
Representing a length of time (duration) using ISO 8601.
Explanation
Durations are represented by the format P[n]Y[n]M[n]DT[n]H[n]M[n]S, where P starts the duration and T precedes the time components.
Examples
1 Hour 30 Mins
Output
PT1H30M
2 Days 5 Hours
Output
P2DT5H
1 Year
Output
P1Y
Code Examples
Template
// Example: 1 hour, 30 minutes, 15 seconds
const duration = 'PT1H30M15S';💡 Tips
- P is the duration designator (Period)
- T is the time designator
- Zero-value components can be omitted
⚠️ Common Pitfalls
- M can mean months OR minutes (position relative to T matters)
- Durations don't represent a specific point in time