プログラミング言語や環境設定を中心としたパソコン関連の技術メモです。
主にシステム開発中に調べたことをメモしています。TIPS的な位置付けで、気が向いたときにちまちま更新していきます。
PHP、date()を使ったら「It is not safe to rely on the system's timezone settings.」とかいうエラーが出た話
結論から書くと、php.iniに

date.timezone = "Asia/Tokyo"

を書けば消えるはずです。

それでは詳細……と言うほどでもないですが、詳細を書いていきます。

月末日を取得するテストコードとして、以下のコードを実行したのですよ。

<?php

$year = 2016;
$month = 2;

echo date('Y-m-d', strtotime('last day of ' . $year . "-" . $month));

そうしたら

PHP Warning: strtotime(): 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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in C:\test\test01.php on line 6

Warning: strtotime(): 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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in C:\test\test01.php on line 6
PHP Warning: date(): 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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in C:\test\test01.php on line 6

Warning: date(): 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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in C:\test\test01.php on line 6

とかいうワーニングが出やがりました。

うん、なんか、いろいろ書いてありますけど、ポイントは

It is not safe to rely on the system's timezone settings.



please set date.timezone to select your timezone.

ですかね。
どうやら「date.timezone」を設定しろ!と言っているようです。

ということで、php.iniに

date.timezone = "Asia/Tokyo"

の記述を追加したら、ワーニングが出なくなりました。

そんな感じ\(--)/
スポンサーリンク
 
このエントリーをはてなブックマークに追加 

category:● PHP  thema:パソコンな日々 - genre:コンピュータ  Posted by ササキマコト 

  関連記事