简体   繁体   中英

PHP Warning: Unknown: It is not safe to rely on the system's timezone settings

I am getting following error whien i use php -i

date

date/time support => enabled "Olson" Timezone Database Version => 0.system Timezone Database => internal PHP Warning: Unknown: 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_timezon
e_set() function. In case you used any of those methods and you are still gettin
g this warning, you most likely misspelled the timezone identifier. We selected
'UTC' for 'UTC/0.0/no DST' instead in Unknown on line 0 Default timezone => UTC

Directive => Local Value => Master Value date.default_latitude => 31.7667 => 31.7667 date.default_longitude => 35.2333 => 35.2333 date.sunrise_zenith => 90.583333 => 90.583333 date.sunset_zenith => 90.583333 => 90.583333 date.timezone => America/Los_Angeles => America/Los_Angeles

My /etc/php.ini has following setting

[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = America/Los_Angeles

; http://www.php.net/manual/en/datetime.configuration.php#ini.date.default-latitude
;date.default_latitude = 31.7667

; http://www.php.net/manual/en/datetime.configuration.php#ini.date.default-longitude
;date.default_longitude = 35.2333

; http://www.php.net/manual/en/datetime.configuration.php#ini.date.sunrise-zenith
;date.sunrise_zenith = 90.583333

; http://www.php.net/manual/en/datetime.configuration.php#ini.date.sunset-zenith
;date.sunset_zenith = 90.583333

PHP version details are as below

PHP 5.3.3 (cli) (built: Dec 5 2013 07:09:40) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

Apache version as below

Server version: Apache/2.2.15 (Unix) Server built: Jul 18 2014 02:31:29

I have restarted Apache multiple times

更改date.timezone = UTC然后运行命令sudo service httpd restart

You could use inside of PHP file:

date_default_timezone_set( "YOUR DATE TIME ZONE");

for example:

date_default_timezone_set( "Europe/Berlin");

List of timezones: http://php.net/manual/en/timezones.php

or if you wish to continue using server timezone but want to hide warnings use:

ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
error_reporting(E_ERROR);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM