如何修复与时区相关的 PHP 错误(function.strtotime 和 function.date)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8811603/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix PHP errors related to timezone (function.strtotime and function.date)
提问by Keefer
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 requiredto 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 requiredto 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.
在此先感谢您的帮助。
回答by Nowhy
date.timezone
in php.ini
can fix this globally.
date.timezone
inphp.ini
可以在全局范围内解决这个问题。
回答by Keefer
Fixed this by putting
通过放置修复了这个问题
date_default_timezone_set('America/New_York');
In the actual file that was complaining.
在抱怨的实际文件中。