在php.ini中设置的默认欧洲时区,但date_default_timezone_get()返回'UTC' [英] Default Europe timezone set in php.ini, but date_default_timezone_get() returns 'UTC'

查看:357
本文介绍了在php.ini中设置的默认欧洲时区,但date_default_timezone_get()返回'UTC'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在 php.ini 文件中设置了默认时区:

  date.timezone =欧洲/罗马

我还重新启动了 httpd 编辑后的服务(服务httpd重新启动),但是当我调用 date_default_timezone_get()时,它将返回'UTC'值。



为什么会这样?



也调用 php_info()显示在<$ c中设置的时区$ c> php.ini



PS。抱歉,我的英文。

解决方案

如果您的代码(包括任何框架)确实不会更改时区,并且您正在从5.1.x到5.3.x的PHP版本下运行,可能在系统的某个位置设置了 TZ 环境变量。然后您的 date.timezone 设置将被忽略



请参见PHP手册页的 date.timezone (重点是我的):


所有日期/时间函数使用的默认时区。 在PHP 5.4.0之前,只有在未设置TZ环境变量的情况下,这才起作用。 […]


检查是否设置了 TZ 环境变量在系统中,您可以使用

  if(isset($ _ ENV ['TZ'])){
echo 'TZ ='。 $ _ENV [’TZ’];
}
else {
echo'TZ not set';
}

或放置

  phpinfo(); 

在代码中的某个位置,并检查其输出最底部的 PHP变量部分。 / p>

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.

解决方案

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.

这篇关于在php.ini中设置的默认欧洲时区,但date_default_timezone_get()返回'UTC'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆