2014年9月29日

php.ini にタイムゾーンを設定する

PHPスクリプトの中で date() などの日時に関連した関数を使うと

It is not safe to rely on the system's timezone settings.
Please use the date.timezone setting, the TZ environment variable 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 'UTC' for now.

のような小うるさい警告がでる。

幾つかのサイトで /etc/php.ini にタイムゾーンを設定するように書かれている。
[Date]
; Defines the default timezone used by the date functions
date.timezone = Asia/Tokyo

しかしこれは上手く行かなかった。 で、上手く行ったのはこれ。
[Date]
; Defines the default timezone used by the date functions
date.timezone =
Japan

PHPのサイトのサポートされているタイムゾーンのリストの中に「Japan」はあるが、「Asia/Tokyo」はなかった。 ごちゃごちゃ言わずに、走行しているホストの現在のタイムゾーン(/etc/localtime)をデフォルトにすればよいのにと思う。

ちなみにPHPのバージョンは 5.5.16。

0 件のコメント:

コメントを投稿