Reputation: 1313
In my php.ini I've set:
date.timezone = "Etc/UTC"
And the server's time is UTC+0 too, but when I try this script to get the timezone:
<?php print(date_default_timezone_get()); ?>
it returns
Europe/Berlin
which is UTC+2
and not UTC+0
and I don't see how it gets there.
Just to clearify:
date()
way to oftenUTC+0
for PHP just by changing the configurationUTC+0
at all times, ignoring Summer-/WintertimeUpvotes: 1
Views: 13166
Reputation: 11
Find "Europe/Berlin" in your php.ini file (get correct path to file with phpinfo();)
In some cases "date.timezone" parameters appears twice in file.
Be sure tu put correct timezones, from here (php timezones)
Upvotes: 0
Reputation: 1313
In the comments, Minesh Patel told me to check if there is something overwriting my option, so I searched through my php.ini for Europe/Berlin
and it turns out there was another date.timezone
-entry that overwrote it.
Upvotes: 2
Reputation: 319
I suggest you to refer this list in order to choose your timezone:
Warning: Do not use any of the timezones listed in the following link, they only exist for backward compatible reasons, besides UTC:
PHP timezones only for backward compatible reasons
It is strongly recommended that you use the correct time zone for your location, such as Europe/Berlin:
date.timezone = "Europe/Berlin"
Upvotes: 0
Reputation: 5939
That line is certainly the correct place to change the default timezone.
Are you actually changing the right php.ini? Some setups can have multiple .ini files. Run phpinfo();
and check Loaded Configuration File to see if it's that file.
Check if there are no other definitions of that parameter in the file. It might override what you've set if you just copy-pasted it in wherever.
Check if the code does not override what you have set in the .ini file. date_default_timezone_set()
sets it (and overrides) in PHP.
Check phpinfo()
for more info on what the current timezone is.
Upvotes: 4
Reputation: 3364
Have you checked the "TZ" environment variable for your web server user? If it is set, the date.timezone php.init setting would not work as expected, like stated in the php manual:
date.timezone string 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. The precedence order for which timezone is used if none is explicitly mentioned is described in the date_default_timezone_get() page.
Upvotes: 1