timmyRS timmyRS - 6 months ago 9
PHP Question

php.ini 'date.timezone' doesn't have any effect

My Problem



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:


  • I have saved the the correct file at the correct path and restarted my server

  • I do not want to modify my scripts, because I already used
    date()
    way to often

  • I want the time to be
    UTC+0
    for PHP just by changing the configuration

  • I want it to be
    UTC+0
    at all times, ignoring Summer-/Wintertime






What solved it



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.

Answer

That line is certainly the correct place to change the default timezone.

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

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

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

  4. Check phpinfo() for more info on what the current timezone is.