php.ini 'date.timezone' doesn't have a

2019-06-03 23:07发布

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

5条回答
淡お忘
2楼-- · 2019-06-03 23:46

I suggest you to refer this list in order to choose your timezone:

PHP timezones

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"
查看更多
冷血范
3楼-- · 2019-06-03 23:54

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.

查看更多
冷血范
4楼-- · 2019-06-04 00:01

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.

查看更多
看我几分像从前
5楼-- · 2019-06-04 00:03

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.

查看更多
forever°为你锁心
6楼-- · 2019-06-04 00:09

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)

查看更多
登录 后发表回答