Format a duration object according as ISO 8601 duration string
Format a duration object according to the ISO 8601 duration standard (https://www.digi.com/resources/documentation/digidocs/90001437-13/reference/r_iso_8601_duration_format.htm)
// CommonJS
var formatISODuration = require('date-fns/formatISODuration')
// ES 2015 import formatISODuration from 'date-fns/formatISODuration'
// ESM
import { formatISODuration } from 'date-fns'
formatISODuration(duration)
| Name | Description |
|---|---|
duration |
the duration to format |
| Description |
|---|
|
The ISO 8601 duration string |
| Type | Description |
|---|---|
TypeError |
Requires 1 argument |
Error |
Argument must be an object |
// Format the given duration as ISO 8601 string
const result = formatISODuration({
years: 39,
months: 2,
days: 20,
hours: 7,
minutes: 5,
seconds: 0
})
//=> 'P39Y2M20DT0H0M0S'
© 2021 Sasha Koss and Lesha Koss
Licensed under the MIT License.
https://date-fns.org/v2.29.2/docs/formatISODuration