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.
We selected 'UTC' for '8.0/no DST' instead...
原因:PHP 默認使用 UTC 時間,與北京時間相差 8 小時。
在入口文件(如 index.php、common.php)最頂部加入:
<?php
date_default_timezone_set('PRC'); // 或 'Asia/Shanghai'
?>
PRC 代表中華人民共和國,等同於 Asia/Shanghai,涵蓋中國大陸標準時間。
php.ini;date.timezone =(分號表示註釋)date.timezone = PRC| 標識符 | 含義 | 適用範圍 |
|---|---|---|
| PRC | 中華人民共和國 | 中國大陸(推薦) |
| Asia/Shanghai | 上海/北京時間 | 中國大陸、港澳台 |
| Asia/Hong_Kong | 香港時間 | 香港特別行政區 |
| Asia/Taipei | 台北時間 | 台灣地區 |
| UTC | 協調世界時 | 國際標準、服務器日誌 |
$dt = new DateTime('now', new DateTimeZone('PRC'));
echo $dt->format('Y-m-d H:i:s');
// 或動態修改
$dt->setTimezone(new DateTimeZone('UTC'));
echo $dt->format('Y-m-d H:i:s'); // 輸出 UTC 時間
PRC 寫成 PPC)會導致回退到 UTC 並再次拋出警告。PRC,舊版請用 Asia/Shanghai。