PHP代码中调用date()时,遇到如题的错误。
原因是:服务器没有配置时区。
解决方法有两种:
1.修改php.ini
You probably need to put the timezone in a configuration line in yourphp.inifile. You should have a block like this in your php.ini file:
[Date]
;Definesthedefaulttimezone usedbythe date functions
; http://php.net/date.timezone
date.timezone =America/New_York
If not, add it (replacing the timezone by yours). After configuring, make sure to restart httpd (service httpd restart).
Here is thelist of supported timezones.
2.修改调用地方的代码
If you cannot modify your php.ini configuration, you could as well use the following snippet at the beginning of your code:
date_default_timezone_set('Africa/Lagos');//or change to whatever timezone you want
The list of timezones can be found athttp://www.php.net/manual/en/timezones.php.
另外,还有奇葩的解决方案:
Add the following in yourindex.phpfile. I first came across this when I moved my application from myXAMPPserver to Apache 2.2 and PHP 5.4...
I would advise you do it in yourindex.phpfile instead of thephp.inifile.
if( ! ini_get('date.timezone') )
{
date_default_timezone_set('GMT');
}
本文介绍了在PHP中使用date()函数时遇到时区设置问题的两种常见解决方法:一是通过修改php.ini文件来全局设定时区;二是直接在脚本开始处设置默认时区。此外还提供了一种针对特定运行环境的特殊解决办法。
1789

被折叠的 条评论
为什么被折叠?



