如果在 php.ini 中设置时区,我是否需要在 PHP 脚本中设置时区?

Do I need to set the timezone in a PHP script, if it is set in php.ini?

phpinfo() 告诉我时区设置正确:

date_default_timezone_get()returns "Europe/Berlin"。因为我在 5.4.35 这应该 return ini 选项(参见 manual)。

我还需要设置时区吗,就像 PHP 的警告告诉我的那样?

Strict Standards: strtotime(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in /your/skript.php on line 249

是的,您应该始终设置时区,即使它是在服务器上设置的。这是必需的,因为您的脚本可能并不总是 运行 在该服务器上,并且如果移动到未设置时区的服务器可能会抛出错误。

通常,UTC 时区是一个不错的选择:

date_default_timezone_set('UTC')