Intl.DateTimeFormat【国際化日時フォーマット】コンストラクタ・プロパティ・メソッド
new Intl.DateTimeFormat()【コンストラクタ】
メモ
- Intl.DateTimeFormat【国際化日時フォーマット】 オブジェクトを生成
- format【フォーマット関数】で文字列に変換
- 数字・表現形式・タイムゾーン 等の指定が可能
- 関連:Date.toLocaleString()【文字列変換 (ロケール)】 ・new Intl.NumberFormat () 【国際化数値フォーマット コンストラクタ】
構文
new Intl.DateTimeFormat([locales [, options]])
戻り値Intl.DateTimeFormat【国際化日時フォーマット】 オブジェクト
localesBCP 47 の言語タグの文字列 または 配列 (省略:デフォルトのロケール) 詳細は下記参照
optionsオプション (実装依存) 詳細は下記参照
BCP 47 の言語タグ
例
値 | 説明 |
---|---|
ja | 日本語 |
ja-JP | 日本語 (日本) |
en-US | 英語 (アメリカ) |
en-GB | 英語 (イギリス) |
de-DE | ドイツ語 (ドイツ) |
fr-FR | フランス語 (フランス) |
以下の Unicode 拡張 数値フォーマット をサポート (実装依存)
値 (-u-nu-○) | 説明 | 例 | コード |
---|---|---|---|
arab | アラビア・インド数字 | ٩ ~ ٠ | U+0660 ~ U+0669 |
arabext | ペルシア数字 | ۰ ~ ۹ | U+06F0 ~ U+06F9 |
bali | バリ数字 | ― | U+1B50 ~ U+1B59 |
beng | ベンガル数字 | ০ ~ ৯ | U+09E6 ~ U+09EF |
deva | デーヴァナーガリー数字 | ० ~ ९ | U+0966 ~ U+096F |
fullwide | 全角数字 | 0 ~ 9 | U+FF10 ~ U+FF19 |
gujr | グジャラート数字 | ૦ ~ ૯ | U+0AE6 ~ U+0AEF |
guru | グルムキー数字 | ੦ ~ ੯ | U+0A66 ~ U+0A6F |
hanidec | 漢数字 | 〇 ~ 九 | U+3007, U+4E00, U+4E8C, U+4E09, U+56DB, U+4E94, U+516D, U+4E03, U+516B, U+4E5D |
khmr | クメール数字 | ០ ~ ៩ | U+17E0 ~ U+17E9 |
knda | カンナダ数字 | ೦ ~ ೯ | U+0CE6 ~ U+0CEF |
laoo | ラオ数字 | ໐ ~ ໙ | U+0ED0 ~ U+0ED9 |
latn | 算用数字 (アラビア数字) | 0 ~ 9 | U+0030 ~ U+0039 |
limb | リンブ数字 | ― | U+1946 ~ U+194F |
mlym | マラヤーラム数字 | ൦ ~ ൯ | U+0D66 ~ U+0D6F |
mong | モンゴル数字 | ᠐ ~ ᠙ | U+1810 ~ U+1819 |
mymr | ミャンマー数字 | ၀ ~ ၉ | U+1040 ~ U+1049 |
orya | オリヤー数字 | 뙦 ~ 뙯 | U+0B66 ~ U+0B6F |
tamldec | タミル数字 | ௦ ~ ௯ | U+0BE6 ~ U+0BEF |
telu | テルグ数字 | ౦ ~ ౯ | U+0C66 ~ U+0C6F |
thai | タイ数字 | ๐ ~ ๙ | U+0E50 ~ U+0E59 |
tibt | チベット数字 | ༠ ~ ༩ | U+0F20 ~ U+0F29 |
以下の Unicode 拡張 カレンダーフォーマット をサポート (実装依存)
値 (-u-ca-○) | 説明 |
---|---|
buddhist | タイ仏教暦 |
chinese | 中国暦 |
coptic | コプト暦 |
ethioaa | ダンギ暦 |
ethiopic | エチオピア暦 |
gregory | グレゴリオ暦 (西暦) |
hebrew | ユダヤ暦 |
indian | インド国定暦 |
islamic | イスラム暦 (1) |
islamicc | イスラム暦 (2) |
iso8601 | ISO 8601 |
japanese | 和暦 |
persian | ペルシア暦 |
roc | 中華民国暦 |
オプション (実装依存)
オプション | 値 (太字:デフォルト値) | 説明 |
---|---|---|
localeMatcher | lookup:Lookupアルゴリズム best fit:最適アルゴリズム | ロケールマッチングアルゴリズム |
formatMatcher | basic:Basicアルゴリズム best fit:最適アルゴリズム | 書式マッチングアルゴリズム |
hour12 | true:12 時間形式 false:24 時間形式 | 12/24 時間形式 |
weekday | narrow:狭い形式 short:短い形式 long:長い形式 | 曜日 |
era | narrow:狭い形式 short:短い形式 long:長い形式 | 年号 |
year | 2-digit:2桁 numeric:ゼロサプレス | 年 |
month | 2-digit:2桁 numeric:ゼロサプレス narrow:狭い形式 short:短い形式 long:長い形式 | 月 |
day | 2-digit:2桁 numeric:ゼロサプレス | 日 |
hour | 2-digit:2桁 numeric:ゼロサプレス | 時 |
minute | 2-digit:2桁 numeric:ゼロサプレス | 分 |
second | 2-digit:2桁 numeric:ゼロサプレス | 秒 |
timeZone | UTC・Asia/Tokyo・America/New_York 等 | タイムゾーン (IANA) |
timeZoneName | short:短い形式 long:長い形式 | タイムゾーン名 |
例
var date = new Date(Date.UTC(2001, (2 - 1), 3, 4, 5, 6));
var dtf = new Intl.DateTimeFormat();
console.log(dtf.format(date));
// 出力:2001/2/3
dtf = new Intl.DateTimeFormat("en-US");
console.log(dtf.format(date));
// 出力:2/3/2001
dtf = new Intl.DateTimeFormat("en-GB");
console.log(dtf.format(date));
// 出力:03/02/2001
var options = { year:'2-digit', month:'2-digit', day:'2-digit', hour12:true, hour:'2-digit', minute:'2-digit', second:'2-digit', weekday:'narrow', timeZone:'UTC', timeZoneName:'long' };
dtf = new Intl.DateTimeFormat("en-US", options);
console.log(dtf.format(date));
// 出力:S, 02/03/01, 4:05:06 AM GMT
options = { year:'numeric', month:'numeric', day:'numeric', hour12:false, hour:'2-digit', minute:'numeric', second:'numeric', weekday:'short', timeZone:'Asia/Tokyo', timeZoneName:'short' };
dtf = new Intl.DateTimeFormat("en-US", options);
console.log(dtf.format(date));
// 出力:Sat, 2/3/2001, 13:05:06 GMT+9
options = { year:'2-digit', month:'narrow', day:'2-digit', hour12:true, hour:'2-digit', minute:'2-digit', second:'2-digit', weekday:'long', timeZone:'Asia/Tokyo', timeZoneName:'long' };
dtf = new Intl.DateTimeFormat("en-US", options);
console.log(dtf.format(date));
// 出力:Saturday, F 03, 01, 1:05:06 PM Japan Standard Time
options = { year:'numeric', month:'short', day:'numeric', hour12:false, hour:'numeric', minute:'numeric', second:'numeric', weekday:'narrow', timeZone:'America/New_York', timeZoneName:'short' };
dtf = new Intl.DateTimeFormat("en-US", options);
console.log(dtf.format(date));
// 出力:F, Feb 2, 2001, 23:05:06 EST
options = { year:'2-digit', month:'long', day:'2-digit', hour12:true, hour:'numeric', minute:'2-digit', second:'2-digit', weekday:'short', timeZone:'America/New_York', timeZoneName:'long' };
dtf = new Intl.DateTimeFormat("en-US", options);
console.log(dtf.format(date));
// 出力:Fri, February 02, 01, 11:05:06 PM Eastern Standard Time
options = { era:'narrow', year:'numeric', month:'numeric', day:'numeric', hour:'numeric', minute:'numeric', second:'numeric', weekday:'narrow', hour12:true, timeZoneName:'long' };
dtf = new Intl.DateTimeFormat("ja-JP-u-ca-japanese", options);
console.log(dtf.format(date));
// 出力:H13年2月3日土 13時05分06秒 日本標準時
options = { era:'short', year:'2-digit', month:'2-digit', day:'2-digit', hour:'2-digit', minute:'2-digit', second:'2-digit', weekday:'short', hour12:false, timeZoneName:'short' };
dtf = new Intl.DateTimeFormat("ja-JP-u-ca-japanese", options);
console.log(dtf.format(date));
// 出力:平成13年02月03日土 13:05:06 JST
options = { era:'long', year:'numeric', month:'numeric', day:'numeric', hour:'numeric', minute:'numeric', second:'numeric', weekday:'long', hour12:true, timeZoneName:'long' };
dtf = new Intl.DateTimeFormat("ja-JP-u-ca-japanese", options);
console.log(dtf.format(date));
// 出力:平成13年2月3日土曜日 13時05分06秒 日本標準時
options = { era:'long', year:'numeric', month:'long', day:'numeric', weekday:'long' };
dtf = new Intl.DateTimeFormat("ja-JP-u-ca-japanese-nu-hanidec", options);
console.log(dtf.format(date));
// 出力:平成一三年二月三日土曜日
dtf = new Intl.DateTimeFormat();
console.log(dtf.format());
// 出力:20xx/x/x 現在日付
関連
- Date.toLocaleString()【文字列変換 (ロケール)】 ・toLocaleDateString ()【ロケール日付文字列変換 (ローカル時刻)】 ・toLocaleTimeString ()【ロケール時刻文字列変換 (ローカル時刻)】
- format【フォーマット関数】
- new Intl.NumberFormat () 【国際化数値フォーマット コンストラクタ】
- ECMA-402 2.0:12.1.2 Intl.DateTimeFormat([ locales [, options ]]) (英語)
- ECMA-402 2.0:12.1.1 InitializeDateTimeFormat (dateTimeFormat, locales, options) (英語)
- RFC 5646:Tags for Identifying Languages (英語)
- RFC 4647:Matching of Language Tags (英語)
- IANA:Time Zone Database (英語)
Intl.DateTimeFormat.prototype.format【フォーマット関数】
メモ
- フォーマット関数を返却
- フォーマット指定:new Intl.DateTimeFormat () 【コンストラクタ】
- Array.map ()【配列変換生成】等の利用可
構文
format(date)
戻り値フォーマット文字列
date日時 (省略:現在日時)
例
// Array.map ()【配列変換生成】利用
var days = [ new Date(2001, (2 - 1), 3), new Date(2011, (3 - 1), 4), new Date(2021, (4 - 1), 5) ];
var dtf = new Intl.DateTimeFormat();
console.log(days.map(dtf.format)); // 出力:["2001/2/3", "2011/3/4", "2021/4/5"]
関連
- Date.toLocaleString()【文字列変換 (ロケール)】 ・toLocaleDateString ()【ロケール日付文字列変換 (ローカル時刻)】 ・toLocaleTimeString ()【ロケール時刻文字列変換 (ローカル時刻)】
- new Intl.DateTimeFormat () 【コンストラクタ】
- ECMA-402 2.0:12.1.2 Intl.DateTimeFormat([ locales [, options ]]) (英語)
- ECMA-402 2.0:12.1.1 InitializeDateTimeFormat (dateTimeFormat, locales, options) (英語)
Intl.DateTimeFormat.prototype.resolvedOptions()【オプション取得】
メモ
- 以下のプロパティを持ったオプション オブジェクトを取得 (デフォルト値がない未指定のプロパティは存在しない)
(new Intl.DateTimeFormat () 【コンストラクタ】も参照)プロパティ 説明 locale BCP47言語タグ calendar Unicode 拡張 カレンダーフォーマット numberingSystem Unicode 拡張 数値フォーマット timeZone タイムゾーン hour12 12/24 時間形式 weekday 曜日 era 年号 year 年 month 月 day 日 hour 時 minute 分 second 秒 timeZoneName タイムゾーン名
構文
resolvedOptions()
戻り値オプション オブジェクト
例
var dtf = new Intl.DateTimeFormat();
console.log(dtf.resolvedOptions());
// 出力:
// object {
// calendar:"gregory"
// day:"numeric"
// locale:"ja"
// month:"numeric"
// numberingSystem:"latn"
// timeZone:"Asia/Tokyo"
// year:"numeric"
// }
console.log(dtf.format());
// 出力:20xx/xx/xx 現在日付
関連
Intl.DateTimeFormat.supportedLocalesOf()【サポート ロケール取得】
メモ
- サポートされるロケールの配列を取得
構文
Intl.DateTimeFormat.supportedLocalesOf( locales [, options])
戻り値サポートされるロケールの配列
localesBCP 47 の言語タグの文字列 または 配列
new Intl.DateTimeFormat () 【コンストラクタ】のlocalesを参照
optionsオプション (localeMatcher【ロケールマッチングアルゴリズム】)
new Intl.DateTimeFormat () 【コンストラクタ】のoptionsを参照