PHPの日付関数でWarningエラー

今さらすぎるんかもしれないですが、知らんかったのでメモ。

PHP5.1.0からデフォルトタイムゾーンを設定しないとエラーになるそうな。
ちなみに私は開発環境作ってるとき、Smartyインストール後だったのでこんなん言われました。

Warning: strftime() [function.strftime]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Tokyo' for '9.0/no DST' instead in C:\わーくすぺーす\libs\Smarty_Compiler.class.php on line 400

対応としては次のどっちかでOK。

  • date_default_timezone_set関数で定義する
  • php.iniで設定する

date_default_timezone_set関数

date_default_timezone_set('Asia/Tokyo');

php.ini

date.timezone = Asia/Tokyo

稼働中うんぬんじゃないので、今回はphp.iniで。