当我请求在服务器上将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>

当前回答

上面来自CtrlX的答案是正确的答案,但它可能不完全有效。 我在php.ini文件中添加了这一行:

date.timezone = "America/Los_Angeles"

但它没有删除所有文件的PHP错误,因为我的一些PHP脚本在子文件夹中。所以我必须编辑.htaccess文件来设置php.ini以递归地使用(在子文件夹中):

suphp_configpath /home/account_name/public_html

其中account_name是你的cpanel帐户名,public_html是你的php.ini文件所在的文件夹。

其他回答

解决这个问题有两种方法

首先,在php.ini文件中输入默认时区

date.timezone = "America/New_York"

在php.ini中设置好时区后,重新启动服务器

其次,改变运行时间 根据您的需要分配时区

date_default_timezone_set('America/New_York');
<? date_default_timezone_set('Europe/Istanbul'); ?>

对于php(或您的位置)。

一个简单的方法,两个时区。

<?php 
$date = new DateTime("2012-07-05 16:43:21", new DateTimeZone('Europe/Paris')); 

date_default_timezone_set('America/New_York'); 

echo date("Y-m-d h:iA", $date->format('U')); 

// 2012-07-05 10:43AM 
?>

我在us-west-2(俄勒冈州)地区托管我的EC2和S3存储桶。当我调用$s3client->listBuckets()来列出我的php中现有的桶时,我得到了异常-“未捕获的异常'异常'与消息'DateTime::__construct():依赖系统的时区设置是不安全的…”。 我做了以下更改,使其工作。分享这些细节,以防有人面临类似的问题,以上任何答案都没有帮助。

Based on documentation @ AWS Configuring Network Time Protocol (NTP), I confirmed ntpd service status is fine by running ntpstat command. If you get error, this link helps you to know what is going wrong. Opened /etc/php.ini file (some may have it in different path based on version of php installed) and found that date.timezone was not set to any value and also it was commented by default. I un-commented by removing ';' before this line and set its value to "UTC" and saved the file. Restarted http and ntp daemons using sudo service httpd restart and sudo service ntpd restart commands.

在此之后,我能够成功地列出桶没有任何例外。希望这能有所帮助。

在你的连接页面中输入如下代码:date_default_timezone_set("Africa/Johannesburg");基于你当前的位置。