简体   繁体   English

设置了date.timezone,为什么PHP仍然显示UTC时间?

[英]Have Set date.timezone, Why PHP still Showing UTC Times?

I've set date.timezone=Australia/Melbourne in my php.ini file. 我在php.ini文件中设置了date.timezone = Australia / Melbourne。 However, I am getting back UTC times. 但是,我又回到了UTC时间。 Details as follows. 细节如下。

As per phpinfo, I edited Loaded Configuration File: /etc/php.ini 根据phpinfo,我编辑了加载的配置文件:/etc/php.ini

I've set: 我已经设定:

date.timezone = Australia/Melbourne

Also tried "Australia/Melbourne" 也尝试过“澳大利亚/墨尔本”

date.timezone isn't in any of the files in this directory: date.timezone不在此目录中的任何文件中:

/etc/php-7.3.d /etc/php-7.3.d

I'm running NGINX and php-fpm I've tried restarting multiple times. 我正在运行NGINX和php-fpm,尝试多次重新启动。

service php-fpm restart 服务php-fpm重新启动

Here is some simple test code: 这是一些简单的测试代码:

echo date_default_timezone_get() . "<br/>";
echo ini_get('date.timezone') . "<br/>";
$date = date('m/d/Y h:i:s a', time());
echo $date;

On another machine with similar setup I get the LOCAL time: 在另一台具有类似设置的机器上,我得到了本地时间:

Australia/Melbourne
Australia/Melbourne
05/02/2019 07:05:05 pm

Whereas, on the problem server I get UTC time: 而在问题服务器上,我得到了UTC时间:

Australia/Melbourne
Australia/Melbourne
05/02/2019 09:05:05 am

Linux says the date time on the problem instance is: Linux表示问题实例的日期时间为:

Thu May  2 19:05:00 AEST 2019

Any suggestions? 有什么建议么?

Thanks brettsh 谢谢布雷特什

Yes, the file I edited (/etc/php.ini) was determined by "Loaded Configuration File" value in phpinfo.php. 是的,我编辑的文件(/etc/php.ini)由phpinfo.php中的“已加载配置文件”值确定。 That's actually a softlink to /etc/php-7.3.ini however, I am editing the correct file. 那实际上是到/etc/php-7.3.ini的软链接,但是,我正在编辑正确的文件。

I'm certain "Australia/Melbourne" is a valid timezone. 我确定“澳大利亚/墨尔本”是有效的时区。

I've since tried: 从那以后我尝试过:

export TZ='Australia/Melbourne'

adding the following to www.conf 将以下内容添加到www.conf

php_admin_value[date.timezone] = Australia/Melbourne

Searched to see if date.timezone set differently elsewhere: 搜索以查看date.timezone在其他地方是否设置了不同的内容:

grep -rn "date.timezone" /etc/

Searched for UTC: 搜索UTC:

grep -rn "UTC" /etc/

Even tried this 甚至尝试过

date_default_timezone_set('Australia/Melbourne');

Maybe this is my problem: https://bugs.php.net/bug.php?id=77582 也许这是我的问题: https : //bugs.php.net/bug.php?id=77582

Turns out it was an issue with that version of PHP. 原来那那个版本的PHP的问题。

All I needed to do was upgrade from PHP 7.3.2 to 7.3.4. 我要做的就是从PHP 7.3.2升级到7.3.4。

I'm running AWS Linux so, I just ran this: 我正在运行AWS Linux,所以我只运行了此命令:

yum update

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

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