LoginSignup
0
0

More than 5 years have passed since last update.

日付フォーマットの罠

Last updated at Posted at 2018-05-25

はじめに

すべての環境でこうなのかどうかわからないが、注意したほうがよいこと(知っておいたほうがよいこと)。

多くの場合 OK: yyyy
多くの場合 NG: YYYY

参考: http://d.hatena.ne.jp/nakamura001/20150102/1420213850

YYYY
ある年における「最初の木曜日を含む週が、その年の第1週である」というルールで年(西暦)を出力。

例えば 2015/1/1 は木曜日なのでその週の日は日曜日~土曜日まで全て2015年の第1週という解釈になり、 2014/12/28(日曜)~2014/12/31(水曜) の時に YYYY を使うと 2015 を返します。

MM
mm

多くの場合 OK: dd
多くの場合 NG: DD

DDは1月1日から何日たったかを示す。

参考: http://www.unicode.org/reports/tr35/tr35-25.html#Date_Format_Patterns

| D | 1..3 | 345 | Day of year |

hh01~12
HH01~24

hhの方は午前(am)か午後(pm)を示す a と一緒に用いないと、例えば朝7時なのか夜7時なのか判別不能になる。

mm
MM

多くの場合 OK: ss
多くの場合 NG: SS

参考: http://www.unicode.org/reports/tr35/tr35-25.html#Date_Format_Patterns

S 1..n 3456 Fractional Second - truncates (like other time fields) to the count of letters. (example shows display using pattern SSSS for seconds value 12.34567)
0
0
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
0
0