LoginSignup
20
13

More than 5 years have passed since last update.

Intl.DateTimeFormat 日付表記option逆引き表

Last updated at Posted at 2017-04-26

Intl.DateTimeFormatを用いた多言語対応の日付フォーマット、どのオプションでどのような出力結果になるのかを、備忘録として表にまとめました。

オプションの一覧と仕様はこちら
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat

確認方法

var date = new Date();
console.log(new Intl.DateTimeFormat('ja-JP', {
  year: 'numeric',
  month: 'narrow',
  day: 'numeric'
}).format(date));

結果

主な環境は
OS: macOS Sierra version 10.12.4
ブラウザ: Google Chrome バージョン 57.0.2987.133 (64-bit)
です。
(他のブラウザもざっと見た感じ、IE以外はだいたい同様の結果だったように思います。)

バグやブラウザ依存の影響が少なく、表記としてもよく使いそうなものに :thumbsup: マークつけました。

出力 locale year month day era 備考
2017/4/1 ja-JP numeric numeric numeric IE、Edgeでは「2017‎年‎4‎月‎1‎日」
:thumbsup: 2017/04/01 ja-JP numeric 2-digit 2-digit IE、Edgeでは‎「2017‎年‎04‎月‎01‎日」
17/04/01 ja-JP 2-digit 2-digit 2-digit
  :thumbsup: 2017年4月1日 ja-JP numeric narrow numeric
2017年4月1日 ja-JP numeric short numeric
2017年4月1日 ja-JP numeric long numeric バグ1
:thumbsup: 平成29年4月1日 ja-JP-u-ca-japanese numeric narrow numeric long
2017年4月1日 zh-Hans-CN numeric narrow numeric バグ2

バグ :bug:

バグ1
特定環境のIEで 「2017‎年‎4‎月‎月1‎日」 月が重複する

バグ2
特定環境のIEで「2017‎年‎4月‎月‎1‎日」 月が重複する

月月のバグは
Windows Server 2008
IE 11.0.9600.18638
などで再現
win8.1 IE11 では再現せず

まとめ

locales × options × ブラウザ で確認がすごい面倒 :rolling_eyes:
しかも特定のlocaleとoptionとブラウザ(IE)でだけバグがあったりする :poop:

20
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
13