UNB/ CS/ David Bremner/ teaching/ cs2613/ books/ mdn/ Reference/ Global Objects/ Intl/ Intl.DurationFormat

The Intl.DurationFormat object enables language-sensitive duration formatting.

Constructor

Static methods

Instance properties

These properties are defined on Intl.DurationFormat.prototype and shared by all Intl.DurationFormat instances.

Instance methods

Examples

Using Intl.DurationFormat

The examples below show how to use the Intl.DurationFormat object to format a duration object with various locales and styles.

const duration = {
  hours: 1,
  minutes: 46,
  seconds: 40,
};

// With style set to "long" and locale "fr-FR"
new Intl.DurationFormat("fr-FR", { style: "long" }).format(duration);
// "1 heure, 46 minutes et 40 secondes"

// With style set to "short" and locale "en"
new Intl.DurationFormat("en", { style: "short" }).format(duration);
// "1 hr, 46 min and 40 sec"

// With style set to "short" and locale "pt"
new Intl.DurationFormat("pt", { style: "narrow" }).format(duration);
// "1h 46min 40s"

Specifications

Browser compatibility

See also