简体   繁体   English

默认欧洲时区在php.ini中设置,但date_default_timezone_get()返回'UTC'

[英]Default Europe timezone set in php.ini, but date_default_timezone_get() returns 'UTC'

I've set in php.ini file the default timezone: 我在php.ini文件中设置了默认时区:

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. 我在编辑(service httpd restart)后也重新启动了httpd服务,但是当我调用date_default_timezone_get() ,它返回'UTC'值。

Why this happens? 为什么会这样?

Also calling php_info() shows the timezone set in php.ini 另外调用php_info()显示在php.ini设置的时区

PS. 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. 如果您的代码(包括任何框架)确实根本没有更改时区,并且您运行的是从5.1.x到5.3.x的PHP版本,那么TZ环境变量可能会设置在您系统的某个位置。 Then your date.timezone setting would be ignored . 然后您的date.timezone设置将被忽略

See the PHP manual page of date.timezone (emphasis mine): 请参阅date.timezone的PHP手册页(强调我的):

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 . 在PHP 5.4.0之前,这仅在未设置TZ环境变量时才有效 […] [...]

To check whether or not the TZ environment variable is set in your system, you could use 要检查系统中是否设置了TZ环境变量,可以使用

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变量”部分。

I just had the same problem. 我刚遇到同样的问题。

In my php.ini , the timezone was well informed: 在我的php.ini时区很清楚:
date.timezone = Europe/Paris

I checked with the php command --ri date 我检查了php命令--ri date
and timezone in php.ini was well taken care of, so the error was not from the ini file. php.ini中的时区很好,所以错误不是来自ini文件。

The error came from the httpd.conf apache's file where is declared the variable PHPIniDir . 该错误来自httpd.conf apache的文件,其中声明了变量PHPIniDir

I had put PHPIniDir "C:\\PHP\\" 我把PHPIniDir "C:\\PHP\\"

You must remove the last back-slash which gives: 你必须删除最后一个反斜杠,它给出:
PHPIniDir "C:\\PHP"

I hope this feedback will help. 我希望这些反馈会有所帮助。

(Just an precision, my environment is : Windows 7, php 5.4.32 and apache 2.2.25) (只是一个精度,我的环境是:Windows 7,php 5.4.32和apache 2.2.25)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM