Since March 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The Intl.DurationFormat() constructor creates Intl.DurationFormat objects.
new Intl.DurationFormat() new Intl.DurationFormat(locales) new Intl.DurationFormat(locales, options)
locales OptionalA string with a BCP 47 language tag or an Intl.Locale instance, or an array of such locale identifiers. The runtime's default locale is used when undefined is passed or when none of the specified locale identifiers is supported. For the general form and interpretation of the locales argument, see the parameter description on the Intl main page.
The following Unicode extension key is allowed:
nuSee numberingSystem.
This key can also be set with options (as listed below). When both are set, the options property takes precedence.
options OptionalAn object containing the following properties, in the order they are retrieved (all of them are optional):
localeMatcherThe locale matching algorithm to use. Possible values are "lookup" and "best fit"; the default is "best fit". For information about this option, see Locale identification and negotiation.
numberingSystemThe numbering system to use for number formatting, such as "arab", "hans", "mathsans", and so on. For a list of supported numbering system types, see Intl.supportedValuesOf(); the default is locale dependent. This option can also be set through the nu Unicode extension key; if both are provided, this options property takes precedence.
styleThe style of the formatted duration. This value is used as the default for all other unit options, and also corresponds to the style option of Intl.ListFormat() when concatenating the list of duration units. Possible values are:
"long"E.g., 1 hour and 50 minutes
"short" (default)E.g., 1 hr, 50 min
"narrow"E.g., 1h 50m
"digital"E.g., 1:50:00
yearsThe style of the formatted years. Possible values are "long", "short", and "narrow"; the default is options.style if it's not "digital", and "short" otherwise.
yearsDisplayWhether to always display years, or only if nonzero. Possible values are "always" and "auto"; the default is "auto" if years is unspecified, and "always" otherwise.
monthsThe style of the formatted months. Possible values are "long", "short", and "narrow"; the default is options.style if it's not "digital", and "short" otherwise.
monthsDisplayWhether to always display months, or only if nonzero. Possible values are "always" and "auto"; the default is "auto" if months is unspecified, and "always" otherwise.
weeksThe style of the formatted weeks. Possible values are "long", "short", and "narrow"; the default is options.style if it's not "digital", and "short" otherwise.
weeksDisplayWhether to always display weeks, or only if nonzero. Possible values are "always" and "auto"; the default is "auto" if weeks is unspecified, and "always" otherwise.
daysThe style of the formatted days. Possible values are "long", "short", and "narrow"; the default is options.style if it's not "digital", and "short" otherwise.
daysDisplayWhether to always display days, or only if nonzero. Possible values are "always" and "auto"; the default is "auto" if days is unspecified, and "always" otherwise.
hoursThe style of the formatted hours. Possible values are "long", "short", "narrow", "numeric", and "2-digit"; the default is options.style if it's not "digital", and "numeric" otherwise.
hoursDisplayWhether to always display hours, or only if nonzero. Possible values are "always" and "auto"; the default is "auto" if hours is unspecified and options.style is not "digital", and "always" otherwise.
minutesThe style of the formatted minutes.
hours is "numeric" or "2-digit", possible values are "numeric" and "2-digit", and "numeric" is normalized to "2-digit"; the default is "numeric"."long", "short", "narrow", "numeric", and "2-digit"; the default is options.style if it's not "digital", and "numeric" otherwise.minutesDisplayWhether to always display minutes, or only if nonzero. Possible values are "always" and "auto"; the default is "auto" if minutes is unspecified and options.style is not "digital", and "always" otherwise.
secondsThe style of the formatted seconds.
minutes is "numeric" or "2-digit", possible values are "numeric" and "2-digit", and "numeric" is normalized to "2-digit"; the default is "numeric"."long", "short", "narrow", "numeric", and "2-digit"; the default is options.style if it's not "digital", and "numeric" otherwise.secondsDisplayWhether to always display seconds, or only if nonzero. Possible values are "always" and "auto"; the default is "auto" if seconds is unspecified and options.style is not "digital", and "always" otherwise.
millisecondsThe style of the formatted milliseconds.
seconds is "numeric" or "2-digit", the only possible value is "numeric"; the default is "numeric"."long", "short", "narrow", and "numeric"; the default is options.style if it's not "digital", and "numeric" otherwise.millisecondsDisplayWhether to always display milliseconds, or only if nonzero.
seconds is "numeric" or "2-digit", the only possible value is "auto"; the default is only "auto" when milliseconds is unspecified."always" and "auto"; the default is "auto" if milliseconds is unspecified, and "always" otherwise.microsecondsThe style of the formatted microseconds.
milliseconds is "numeric", the only possible value is "numeric"; the default is "numeric"."long", "short", "narrow", and "numeric"; the default is options.style if it's not "digital", and "numeric" otherwise.microsecondsDisplayWhether to always display microseconds, or only if nonzero.
milliseconds is "numeric", the only possible value is "auto"; the default is only "auto" when microseconds is unspecified."always" and "auto"; the default is "auto" if microseconds is unspecified, and "always" otherwise.nanosecondsThe style of the formatted nanoseconds.
microseconds is "numeric", the only possible value is "numeric"; the default is "numeric"."long", "short", "narrow", and "numeric"; the default is options.style if it's not "digital", and "numeric" otherwise.nanosecondsDisplayWhether to always display nanoseconds, or only if nonzero.
microseconds is "numeric", the only possible value is "auto"; the default is only "auto" when nanoseconds is unspecified."always" and "auto"; the default is "auto" if nanoseconds is unspecified, and "always" otherwise.fractionalDigitsNumber of how many fractional second digits to display in the output. Possible values are from 0 to 9; the default is undefined (include as many fractional digits as necessary).
RangeErrorThrown if locales or options contain invalid values.
For each time segment, an Intl.NumberFormat object is constructed under the hood. It uses the following options (see Intl.NumberFormat() for details):
numberingSystem: the value of options.numberingSystem
When milliseconds, microseconds, or nanoseconds uses the "numeric" style, the following options are also used:
minimumFractionDigits: 0 when options.fractionalDigits is undefined, options.fractionalDigits otherwisemaximumFractionDigits: 9 when options.fractionalDigits is undefined, options.fractionalDigits otherwiseroundingMode: "trunc"
When the time segment uses the "2-digit" style, the following options are also used:
minimumIntegerDigits: 2
When the time segment uses the "long", "short", or "narrow" style, the following options are also used:
style: "unit" when "long", "short", or "narrow" is specified, undefined otherwiseunit: the currently formatted unit ("years", "days", "nanoseconds", etc.)unitDisplay: the value of the time segment style ("long", "short", or "narrow")const duration = {
hours: 2,
minutes: 20,
seconds: 35,
};
console.log(new Intl.DurationFormat("pt", { style: "long" }).format(duration));
// "2 horas, 20 minutos e 35 segundos"
| Desktop | Mobile | Server | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | Bun | Deno | Node.js | |
DurationFormat |
129 | 129 | 136 | 115 | 16.4 | 129 | 136 | 86 | 16.4 | 28.0 | 129 | 16.4 | 1.0.3 | 1.46 | 23.0.0 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat