大网数据广告活动
Web 标准与前端开发

Intl.DurationFormat

· 52CE 我爱测

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

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

Constructor

  • Intl/DurationFormat/DurationFormat
    • : Creates a new Intl.DurationFormat object.

Static methods

  • Intl/DurationFormat/supportedLocalesOf
    • : Returns an array containing those of the provided locales that are supported without having to fall back to the runtime's default locale.

Instance properties

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

  • Object/constructor
    • : The constructor function that created the instance object. For Intl.DurationFormat instances, the initial value is the Intl/DurationFormat/DurationFormat constructor.
  • Intl.DurationFormat.prototype[Symbol.toStringTag]
    • : The initial value of the [Symbol.toStringTag] property is the string "Intl.DurationFormat". This property is used in Object.prototype.toString().

Instance methods

  • Intl/DurationFormat/format
    • : Formats a duration according to the locale and formatting options of this DurationFormat object.
  • Intl/DurationFormat/formatToParts
    • : Returns an Array of objects representing the formatted duration in parts.
  • Intl/DurationFormat/resolvedOptions
    • : Returns a new object with properties reflecting the locale and formatting options computed during initialization of the object.

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 "narrow" and locale "pt"
new Intl.DurationFormat("pt", { style: "narrow" }).format(duration);
// "1 h 46 min 40 s"

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。