简体   繁体   English

PHP 柏林时间已关闭

[英]PHP time for Berlin is off

I have the following PHP-code:我有以下 PHP 代码:

<!DOCTYPE html>
<html>
<body>

<?php
$date = date_create("2020-04-27T15:27:59+00:00", new DateTimeZone("Europe/Berlin"));
echo $date->setTimezone(new DateTimeZone("Europe/Berlin"))->format('Y-m-d H:i:s');
?>

</body>
</html>

I expected my output to be: 2020-04-27 15:27:59 Instead I'm getting: 2020-04-27 17:27:59 So where are the two hours plus coming from?我希望我的 output 是: 2020-04-27 15:27:59 而我得到的是: 2020-04-27 17:27:59 那么这两个多小时从何而来? I don't get what I'm doing wrong.我不明白我做错了什么。

It's because Berlin is 2 hours ahead from 00:00 (UTC) starting from last Sunday of March .这是因为从3 月的最后一个星期日开始,柏林比 00:00 (UTC) 提前 2 小时。 Since you specify 00:00 (UTC) timezone, and then convert it to Europe/Berlin, it becomes +2 hours.由于您指定 00:00 (UTC) 时区,然后将其转换为欧洲/柏林,它变为 +2 小时。

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

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