如何修复与时区相关的PHP错误(function.strtotime和function.date)

时间:2022-10-16 09:56:23

Upgrading to a new server, I two repeated errors:

升级到新服务器,我两次重复错误:

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 'EST/-5.0/no DST' instead in...

警告:strtotime()[function.strtotime]:依赖系统的时区设置是不安全的。您需要使用date.timezone设置或date_default_timezone_set()函数。如果您使用了这些方法中的任何一种并且仍然收到此警告,则很可能拼错了时区标识符。我们在'EST / -5.0 / no DST'中选择'America / New_York'代替......

and

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 'EST/-5.0/no DST' instead in

警告:date()[function.date]:依赖系统的时区设置是不安全的。您需要使用date.timezone设置或date_default_timezone_set()函数。如果您使用了这些方法中的任何一种并且仍然收到此警告,则很可能拼错了时区标识符。我们在'EST / -5.0 / no DST'中选择'America / New_York'代替

How do I go about fixing these?

我该如何解决这些问题?

Code in question is this:

有问题的代码是这样的:

'date' => date("Y-M-d",strtotime($Array['_dateCreated'])),

I've tried putting this in an include at the top of all my pages:

我已经尝试将它放在我所有页面顶部的包含中:

<?php
date_default_timezone_set('America/New_York');
?>

Thanks in advance for your help.

在此先感谢您的帮助。

2 个解决方案

#1


28  

date.timezone in php.ini can fix this globally.

php.ini中的date.timezone可以全局解决这个问题。

#2


27  

Fixed this by putting

修正此问题

date_default_timezone_set('America/New_York');

In the actual file that was complaining.

在抱怨的实际文件中。

#1


28  

date.timezone in php.ini can fix this globally.

php.ini中的date.timezone可以全局解决这个问题。

#2


27  

Fixed this by putting

修正此问题

date_default_timezone_set('America/New_York');

In the actual file that was complaining.

在抱怨的实际文件中。