Intl.DurationFormat
Intl.DurationFormat 物件支援實現語言敏感的持續時間格式化。
建構函式
Intl.DurationFormat()-
建立一個新的
Intl.DurationFormat物件。
靜態方法
Intl.DurationFormat.supportedLocalesOf()-
返回一個數組,其中包含提供的區域設定中受支援的那些區域設定,而無需回退到執行時預設區域設定。
例項屬性
這些屬性定義在 Intl.DurationFormat.prototype 上,並由所有 Intl.DurationFormat 例項共享。
Intl.DurationFormat.prototype.constructor-
建立例項物件的建構函式。對於
Intl.DurationFormat例項,初始值是Intl.DurationFormat建構函式。 Intl.DurationFormat.prototype[Symbol.toStringTag]-
[Symbol.toStringTag]屬性的初始值是字串"Intl.DurationFormat"。此屬性用於Object.prototype.toString()。
例項方法
Intl.DurationFormat.prototype.format()-
獲取器函式,用於根據此
DurationFormat物件的區域設定和格式化選項來格式化持續時間。 Intl.DurationFormat.prototype.formatToParts()-
返回一個物件陣列,其中包含格式化持續時間的分成部分。
Intl.DurationFormat.prototype.resolvedOptions()-
返回一個新物件,其屬性反映在物件初始化過程中計算出的語言環境和格式化選項。
示例
使用 Intl.DurationFormat
下面的示例展示瞭如何使用 Intl.DurationFormat 物件,根據各種區域設定和樣式格式化持續時間物件。
js
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"
規範
| 規範 |
|---|
| Intl.DurationFormat # durationformat-objects |
瀏覽器相容性
載入中…