phpにて
timezoneのデフォルトは、以下のようにドイツのベルリンが標準になっている。
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Europe/Berlin"
そのため、phpで
.php
<?php
echo date('Y-m-d H:i:s');
と出力しても日本時間ではない場合があるので注意が必要。
変更方法
①__はじめに設定ファイルを確認する。__
phpファイル内で
.php
<?php
phpinfo();
と出力するか、MAMPにてwebPageを開いたtools内のinfoを確認する。
②__そこに表示される以下のパスが設定ファイルのパスである。__
③php.ini内の設定の変更
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Europe/Berlin" <--ここを変更
↓
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Asia/Tokyo" <--ここを変更
④MAMPの再起動
Default timezone => Asia/Tokyoになっていることが確認できる。
注意点
上記の方法をやってみても変更ができない場合は、以下の方法を試してみる。
①間違ったファイルパスのphp.iniを変更してないか?
②スペルミスはないか?
③再起動はしたか?
④意外なミスとして以下がある。
最初の段階でphp.iniのdate.timezoneの行の先頭に ; がついている場合がある。
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
; date.timezone = "Asia/Tokyo"
; はコメントアウトという意味なので、注意が必要。
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Asia/Tokyo"
; が取れているかの確認をしてみよう!!