如何解决以下聪明的错误? (或php 5.3.8)

时间:2011-09-13 00:34:05

标签: php smarty

我有这个错误

Warning: date() [function.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 'America/New_York' for 'EDT/-4.0/DST' instead in /var/www/html/includes/functions.php on line 1444

和这个错误

Warning: strtotime() [function.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 'America/New_York' for 'EDT/-4.0/DST' instead in /var/www/html/includes/templatelib/plugins/modifier.date_format.php on line 37

和这个错误

Warning: strtotime() [function.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 'America/New_York' for 'EDT/-4.0/DST' instead in /var/www/html/includes/functions.php on line 3538

我已经读过,第一个是由最新的php版本引起的,但其他2个是破坏性的错误

我在durpal论坛上看过,与第一个类似的错误,修复是编辑php.ini

并且修复是添加date.timezone = "America/New_York"这样的时区对我不起作用

修改

好的,所以你们都同意1个解决方案,我应该编辑我的源代码,是否应该更改php.ini中的任何内容?因为到目前为止我一直试图从php.ini修复它并且无法正常工作

修正了

我不得不改变我的vps时区

ln -sf /usr/share/zoneinfo/GMT /etc/localtime

并使用php.ini做同样的事情,我也忘了重启apache lol:D

3 个答案:

答案 0 :(得分:2)

你试过吗

date_default_timezone_set('Europe/London');

在PHP脚本的开头? (当然,将'欧洲/伦敦'改为无论您身在何处!)

答案 1 :(得分:2)

如果您不想在脚本开头使用date_default_timezone_set,则应确保PHP实际上正确加载了该配置选项。检查phpinfo()的输出。另一个潜在的问题:我不知道你的托管设置,但我有不同配置的多个PHP ini文件,有时我编辑错误的。方便地phpinfo();还告诉你它正在使用的.ini文件,以便你可以仔细检查。

也就是说,其他人提出的date_default_timezone_set选项几乎可以保证有效。

答案 2 :(得分:1)

尝试:

把它放在第一行

date_default_timezone_set("America/New_York");