The duration specification in ISO 8601 format is essential for representing time intervals in a standardized manner. Below, we show you how to do it simply.
ISO 8601 is an international standard that defines the representation of dates and durations. In this case, we will focus on the duration specification.
To specify a duration in ISO 8601 format, use the format P[nY][nM][nD][T[nH][nM][nS]]
:
P3Y6M4DT12H30M5S
In this example, the duration is 3 years, 6 months, 4 days, 12 hours, 30 minutes, and 5 seconds.
The format components include:
Let's see a practical example of how to use this notation in a programming context:
const duration = 'P2DT4H30M';
In this case, the duration is 2 days, 4 hours, and 30 minutes.
The duration specification in ISO 8601 format provides a consistent and clear way to represent time intervals. Be sure to use this standard in your projects for greater coherence and understanding.
Jorge García
Fullstack developer