Intl.DurationFormat
Baseline
2025
最近利用可能
March 2025以降、この機能は最新のバージョンの端末およびブラウザーで動作します。古い端末やブラウザーでは動作しないことがあります。
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()-
書式化された経過時間の各部分を表すオブジェクトの配列 (
Array) を返します。 Intl.DurationFormat.prototype.resolvedOptions()-
オブジェクトの初期化時に計算されたロケールや書式化オプションを反映したプロパティを持つ、新しいオブジェクトを返します。
例
>Intl.DurationFormat の使用
以下の例は、Intl.DurationFormat オブジェクトを使用して、さまざまなロケールおよびスタイルで再生時間オブジェクトを書式化する方法を示しています。
const duration = {
hours: 1,
minutes: 46,
seconds: 40,
};
// スタイルを "long" に、ロケールを "fr-FR" に設定
new Intl.DurationFormat("fr-FR", { style: "long" }).format(duration);
// "1 heure, 46 minutes et 40 secondes"
// スタイルを "short" に、ロケールを "en" に設定
new Intl.DurationFormat("en", { style: "short" }).format(duration);
// "1 hr, 46 min and 40 sec"
// スタイルを "narrow" に、ロケールを "pt" に設定
new Intl.DurationFormat("pt", { style: "narrow" }).format(duration);
// "1 h 46 min 40 s"
仕様書
| 仕様書 |
|---|
| Intl.DurationFormat> # durationformat-objects> |