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.
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.
Here's the code:
<?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);
?>
And here's the output that this genereates:
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
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
And this is the dummy code on my server in action: http://arma.jianji.de/phptest.php
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?
Thank you in advance for your help!
Update
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');
Additionally, I've added "Europe/London" as default timezone in my php.ini.
The issue still persists: http://arma.jianji.de/phptest_default.php