揮発性のメモ2

http://d.hatena.ne.jp/iww/

strtotime()はy/m/d形式を誤認する

誤認というかアメリカンな感じ

<?
    print date("Y/m/d\n",strtotime( "2012年11月01日" ));
    print date("Y/m/d\n",strtotime( "2012/11/01" ));
    print date("Y/m/d\n",strtotime( "12/11/01" ));
    print date("Y/m/d\n",strtotime( "12-11-01" ));
?>
1970/01/01
2012/11/01
2001/12/11
2012/11/01

日付をスラッシュ区切りで表現したときの年月日の解釈は 日本とアメリカとヨーロッパで 3種類に分かれる。したがって、年が2桁にされていると、なにがなんだかわからなくなる。

ハイフン区切りであれば、多分ISO 8601のおかげで「年-月-日」であると認識される。