当我请求在服务器上将PHP版本从5.2.17 更新到PHP 5.3.21 时,我收到此错误.
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Warning</p>
<p>Message: 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</p>
<p>Filename: libraries/Log.php</p>
<p>Line Number: 86</p>
</div>
Warning: 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 /filelocation right here/system/libraries/Log.php on line 86
Warning: 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 /filelocation right here/system/libraries/Log.php on line 99
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Warning</p>
<p>Message: 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</p>
<p>Filename: libraries/Log.php</p>
<p>Line Number: 99</p>
</div>
Run Code Online (Sandbox Code Playgroud)
Ctr*_*rlX 548
您可能需要将时区放在php.ini文件的配置行中.你应该在php.ini文件中有一个这样的块:
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = America/New_York
Run Code Online (Sandbox Code Playgroud)
如果没有,请添加它(由您的时区替换).配置完成后,请确保重新启动httpd(service httpd restart).
以下是支持的时区列表.
Bab*_*emi 196
如果您无法修改php.ini配置,您也可以在代码的开头使用以下代码段:
date_default_timezone_set('Africa/Lagos');//or change to whatever timezone you want
Run Code Online (Sandbox Code Playgroud)
时区列表可在http://www.php.net/manual/en/timezones.php找到.
小智 70
在您的index.php文件中添加以下内容.当我将我的应用程序从XAMPP服务器移动到Apache 2.2和PHP 5.4 时,我第一次遇到这个问题...
我建议你在你的index.php文件中而不是php.ini文件中进行.
if( ! ini_get('date.timezone') )
{
date_default_timezone_set('GMT');
}
Run Code Online (Sandbox Code Playgroud)
小智 18
<? print(gmdate("Y")); ?>
Run Code Online (Sandbox Code Playgroud)
代替
<? print(date("Y")); ?>
Run Code Online (Sandbox Code Playgroud)
为我工作(显示当前年份,不再显示错误消息).(感谢克里斯上面)
Chr*_*ris 15
如果这些不是您的选择
php.ini.date_default_timezone电话.而不是date你可以使用gmdate.
gmdate( "Y" )当我需要一年的版权信息时,我已经习惯了.
小智 14
如果您正在使用CodeIgniter并且无法更改php.ini,我将以下内容添加到index.php的开头:
date_default_timezone_set('GMT');
Run Code Online (Sandbox Code Playgroud)
Sha*_*lam 13
我始终将这一行保留在codeigniter的根目录中index.php.因此我的代码可以在任何服务器上运行
date_default_timezone_set('Asia/Dhaka');
Run Code Online (Sandbox Code Playgroud)
Joh*_*art 11
@Justis向我指出了正确的方向,但他的代码对我不起作用.这样做:
// set the default timezone if not set at php.ini
if (!date_default_timezone_get('date.timezone')) {
// insert here the default timezone
date_default_timezone_set('America/New_York');
}
Run Code Online (Sandbox Code Playgroud)
文档:http://www.php.net/manual/en/function.date-default-timezone-get.php
此解决方案不仅适用于没有完整系统访问权限的用户.除了您之外,任何脚本都必须提供给任何其他人.当您将脚本分发给其他人时,您永远不知道脚本将在什么服务器上运行.
小智 5
我不得不把它放在双引号中。
date_default_timezone_set("America/Los_Angeles"); // default time zone
Run Code Online (Sandbox Code Playgroud)
小智 5
这个问题一直困扰着我一段时间,因为我试图将“ createbucket.php”脚本注入作曲家,而且我一直被告知时区不正确。
最后,解决该问题的唯一方法是:
$ sudo nano /etc/php.ini
搜索时区
[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = UTC
Run Code Online (Sandbox Code Playgroud)
确保删除 ;
然后最后
$ sudo service httpd restart
Run Code Online (Sandbox Code Playgroud)
而且你会很好:)