简体   繁体   中英

PHP time for Berlin is off

I have the following PHP-code:

<!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? 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 . Since you specify 00:00 (UTC) timezone, and then convert it to Europe/Berlin, it becomes +2 hours.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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