php像UTC一样编译时区Europe/Berlin [英] php compiles timezone Europe/Berlin like UTC

查看:450
本文介绍了php像UTC一样编译时区Europe/Berlin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天一直在为一个奇怪的问题而苦苦挣扎.由于某种原因,我的服务器假装时区欧洲/柏林"为UTC(应为UTC + 1).例如,如果我将时区设置为欧洲/布鲁塞尔",它将正确转换时间.

I've been struggling with a weird problem today. For some reason my server pretends that the timezone 'Europe/Berlin' is UTC (it should be UTC+1). If I set the timezone to 'Europe/Brussels' for example, it converts the time correctly.

我已经创建了一些伪代码来测试我的服务器和在线编译器.当编译器正常工作时(我使用了 http://sandbox.onlinephpfunctions.com/),我的服务器仍然存在此问题.

I've created some dummy code to test my server and on an online compiler. While the compiler works (I've used http://sandbox.onlinephpfunctions.com/), my server persists to have this issue.

代码如下:

<?php
$time = 'now';

$timezone1 = 'Europe/London';
$timezone2 = 'Europe/Berlin';
$timezone3 = date_default_timezone_get();
$timezone4 = 'Europe/Brussels';

$dateTime1 = new \DateTime($time, new DateTimeZone($timezone1));
$timeParsed1 = $dateTime1->format('Y-m-d H:i:sP');

$dateTime2 = new \DateTime($time, new DateTimeZone($timezone2));
$timeParsed2 = $dateTime2->format('Y-m-d H:i:sP');

$dateTime3 = new \DateTime($time, new DateTimeZone($timezone3));
$timeParsed3 = $dateTime3->format('Y-m-d H:i:sP');

$dateTime4 = new \DateTime($time, new DateTimeZone($timezone4));
$timeParsed4 = $dateTime4->format('Y-m-d H:i:sP');

echo($timezone1 . ': ' . $timeParsed1 . '<br>' . $timezone2 . ': ' . $timeParsed2 . '<br>' . $timezone3 . ': ' . $timeParsed3 . '<br>' . $timezone4 . ': ' . $timeParsed4);
?>

这是生成的输出:

Europe/London: 2017-01-26 01:24:18+00:00
Europe/Berlin: 2017-01-26 01:24:18+00:00
UTC: 2017-01-26 01:24:18+00:00
Europe/Brussels: 2017-01-26 02:24:18+01:00

我一直在尝试寻找原因,并在Stackoverflow上进行了搜索,但找不到原因.这是指向我的phpinfo()的链接: http://arma.jianji.de/phpinfo.php

I've been trying to find the cause for this and searched here on Stackoverflow, but I couldn't find the reason. Here's a link to my phpinfo(): http://arma.jianji.de/phpinfo.php

这是我服务器上运行的伪代码: http://arma.jianji.de /phptest.php

And this is the dummy code on my server in action: http://arma.jianji.de/phptest.php

服务器是我最近使用Ubtuntu 16 LTS和Plesk Onyx设置的.服务器默认时区设置为伦敦.

The server has been recently set up by me using Ubtuntu 16 LTS and Plesk Onyx. The server default timezone is set to London.

不幸的是,我一直无法找到原因.你有主意吗?

Unfortunately, I've been unable to find the reason for this. Do you have an idea?

预先感谢您的帮助!

更新

由于已经提出了很多建议,所以我创建了一个测试,使用以下方法设置了默认时区:

Because this has been brought up quite a lot, I've created a test where I set a default timezone by using:

date_default_timezone_set('Europe/Brussels');

此外,我在php.ini中添加了欧洲/伦敦"作为默认时区.

Additionally, I've added "Europe/London" as default timezone in my php.ini.

问题仍然存在: http://arma.jianji.de/phptest_default.php

推荐答案

正如@RuslanOsmanov所指出的那样,欧洲/柏林的时区数据不正确.我可以通过使用

As @RuslanOsmanov kindly pointed out, the timezone data for Europe/Berlin was incorrect. I was able to verify this by using

zdump -V Europe/Berlin | grep 2017

为了解决此问题,我重新安装了tzdata来解决此问题.

In order to fix this, I performed a reinstall of tzdata which fixed the problem.

 apt-get --reinstall install tzdata

这篇关于php像UTC一样编译时区Europe/Berlin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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