PHP message: PHP Warning: strftime(): It is not safe to rely on the system's timezone settings

PHP站点运行报错:

PHP message: PHP Warning:  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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /var/www/scgossip/libs/sysplugins/smarty_internal_templatecompilerbase.php on line 183

原因:没有设定系统的timezone。

解决办法:

php.ini中找到date.timezone,修改为 date.timezone = PRC,后保存,重启php服务器(如httpd)即可。

说明:date.timezone 是 PHP 5.1 中新增加的配置文件参数,默认 date.timezone 是被注释掉的,也就是默认时区是 utc,lnmp 改为了 date.timezone = PRC,这样可以解决时间相差八小时的问题。

在 ext/date/lib/timezonemap.h 中看到如下代码

{ "cst",   0,  28800, "Asia/Chongqing"                },
{ "cst",   0,  28800, "Asia/Chungking"                },
{ "cst",   0,  28800, "Asia/Harbin"                   },
{ "cst",   0,  28800, "Asia/Kashgar"                  },
{ "cst",   0,  28800, "Asia/Macao"                    },
{ "cst",   0,  28800, "Asia/Macau"                    },
{ "cst",   0,  28800, "Asia/Shanghai"                 },
{ "cst",   0,  28800, "Asia/Taipei"                   },
{ "cst",   0,  28800, "Asia/Urumqi"                   },
{ "cst",   0,  28800, "PRC"                           },
{ "cst",   0,  28800, "ROC"                           },

所以 date.timezone = Asia/Shanghai 也是可以的。



相关推荐

    我的回答