“date(): It is not safe to rely on the system'

2018-12-31 16:29发布

I got this error when I requested to update the PHP version from 5.2.17 to PHP 5.3.21 on the server.

<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>

标签: php timezone
21条回答
伤终究还是伤i
2楼-- · 2018-12-31 16:49

For docker user: Create a local timezone.ini file in your project, set up the config in docker-compose.yml,

    volumes:
        - "./docker/config/timezone.ini:/usr/local/etc/php/conf.d/timezone.ini"

timezone.ini

    date.timezone=Australia/Sydney
查看更多
姐姐魅力值爆表
3楼-- · 2018-12-31 16:51

Add the following in your index.php file. I first came across this when I moved my application from my XAMPP server to Apache 2.2 and PHP 5.4...

I would advise you do it in your index.php file instead of the php.ini file.

if( ! ini_get('date.timezone') )
{
    date_default_timezone_set('GMT');
}
查看更多
无与为乐者.
4楼-- · 2018-12-31 16:52

If you using Plesk, try it, First, Open PHP Settings, at the bottom of page, change date.timezone from DEFAULT to UTC.

enter image description here

enter image description here

查看更多
旧时光的记忆
5楼-- · 2018-12-31 16:53

In my particular case, I have PHP configured to use PHP-FPM (FastCGI Process Manager). When executing phpinfo() from CLI I saw correct timezone that I had set in the php.ini, however it was still incorrect in the browser and causing my code to fail. I simply needed to restart the php-fpm service on the server.

service rh-php56-php-fpm restart

You may also need to restart the httpd service if you edited the php.ini

service httpd restart
查看更多
只靠听说
6楼-- · 2018-12-31 16:54

I always keep this line inside codeigniter's root index.php.So that my code works at any server

date_default_timezone_set('Asia/Dhaka');

List of Supported Timezones here

查看更多
骚的不知所云
7楼-- · 2018-12-31 16:56

A quick solution whilst your rectify the incompatibilities, is to disable error reporting in your index.php file:

Insert the line below into your index.php below define( ‘_JEXEC’, 1 );

error_reporting( E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR |
E_COMPILE_WARNING );
查看更多
登录 后发表回答