JavaScript

Intl.DateTimeFormat オブジェクト


編集:2023.01.09 by T.A.

[Edge]。→

言語に応じた日時の書式化を可能にするオブジェクト。

コンストラクター
new Intl.DateTimeFormat([locales[, options]])
新しい Intl.DateTimeFormat オブジェクトを生成して返します。
静的メソッド
Intl.DateTimeFormat.supportedLocalesOf(locales[, options])
指定のロケールで、日時の書式化で対応しているロケール タグの文字列の配列で返します。
インスタンスメソッド
Intl.DateTimeFormat.format(date)
Intl.DateTimeFormat により指定の日時を書式化して文字列で返します。
Intl.DateTimeFormat.formatToParts([date])
Intl.DateTimeFormat により指定の日時を書式化した各部分データ オブジェクトの配列で返します。
Intl.DateTimeFormat.resolvedOptions()
Intl.DateTimeFormat により日時の整形に関与するプロパティと値のオブジェクトを返します。
Intl.DateTimeFormat.formatRange(startDate, endDate)
Intl.DateTimeFormat により指定の日時範囲に書式化した文字列を返します。
Intl.DateTimeFormat.formatRangeToParts(startDate, endDate)
Intl.DateTimeFormat により指定の日時範囲を書式化した各部分データ オブジェクトの配列で返します。

DA=new Intl.DateTimeFormat('ja-JP', {era:'long', year:'numeric'}); //整形:時代、年。
D=DA.format(new Date('2020'));  //日付文字列で指定したDateを整形。
	//=[string]:西暦2020年
D=DA.format(new Date(-10, 0));  //2つ以上の数値で指定したDateを整形。
	//=[string]:紀元前11年
D=DA.formatRange(new Date('2020'), new Date('2022'));  //開始Date、終了Dateで範囲指定で整形。
	//=[string]:西暦2020年~2022年

テスト