Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default Europe timezone set in php.ini, but date_default_timezone_get() returns 'UTC'

Tags:

date

timezone

php

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.

like image 326
Andres7X Avatar asked Aug 08 '12 17:08

Andres7X


1 Answers

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.

like image 145
Jürgen Thelen Avatar answered Oct 04 '22 14:10

Jürgen Thelen