Reputation: 165
I've set in php.ini file the default timezone:
date.timezone = Europe/Rome
I've also restarted httpd
service after the edit (service httpd restart), but when I call date_default_timezone_get()
, it returns 'UTC' value.
Why this happens?
Also calling php_info()
shows the timezone set in php.ini
PS. Sorry for my English.
Upvotes: 10
Views: 14801
Reputation: 5772
I just had the same problem.
In my php.ini
, the timezone was well informed:
date.timezone = Europe/Paris
I checked with the php command --ri date
and timezone in php.ini
was well taken care of, so the error was not from the ini file.
The error came from the httpd.conf
apache's file where is declared the variable PHPIniDir.
I had put PHPIniDir "C:\PHP\"
You must remove the last back-slash which gives:
PHPIniDir "C:\PHP"
I hope this feedback will help.
(Just an precision, my environment is : Windows 7, php 5.4.32 and apache 2.2.25)
Upvotes: 0
Reputation: 12727
If your code (including any frameworks) really does not change the timezone at all and you're running under a PHP version from 5.1.x to 5.3.x, it's possible, that the TZ
environment variable is set somewhere in your system. Then your date.timezone
setting would be ignored.
See the PHP manual page of date.timezone
(emphasis mine):
The default timezone used by all date/time functions. Prior to PHP 5.4.0, this would only work if the TZ environment variable was not set. […]
To check whether or not the TZ
environment variable is set in your system, you could use
if (isset($_ENV['TZ'])) {
echo 'TZ=' . $_ENV['TZ'];
}
else {
echo 'TZ not set';
}
or put
phpinfo();
somewhere in your code and check the "PHP Variables" section at the very bottom of its output.
Upvotes: 3