Environment: PHP 7.3.13RC1; CentOS 7.7.1908; Server Timezone "Europe/Berlin"
Observation:
The following PHP script:
$date1=date_create("now");
$date2=date_create("now");
$date3=date_create("now");
$tz1=new DateTimeZone("Europe/Berlin");
$tz2=new DateTimeZone("UTC");
$tz3=new DateTimeZone("GMT");
echo "Current Set Times:","\n";
echo "Date 1: ", $date1->format(DateTime::ATOM), "\n";
echo "Date 2: ", $date2->format(DateTime::ATOM), "\n";
echo "Date 3: ", $date3->format(DateTime::ATOM), "\n";
$date1->setTimezone($tz1);
$date2->setTimezone($tz2);
$date3->setTimezone($tz3);
echo "Times with new Time Zone Set", "\n";
echo "Date 1: ", $date1->format(DateTime::ATOM), "\n";
echo "Date 2: ", $date2->format(DateTime::ATOM), "\n";
echo "Date 3: ", $date3->format(DateTime::ATOM), "\n";
Results in this output:
Current Set Times:
Date 1: 2019-12-21T22:01:00+01:00
Date 2: 2019-12-21T22:01:00+01:00
Date 3: 2019-12-21T22:01:00+01:00
Times with new Time Zone Set
Date 1: 2019-12-21T22:01:00+01:00
Date 2: 2019-12-21T22:01:00+00:00
Date 3: 2019-12-21T21:01:00+00:00
Whereas I would expect to see the following output:
Current Set Times:
Date 1: 2019-12-21T22:01:00+01:00
Date 2: 2019-12-21T22:01:00+01:00
Date 3: 2019-12-21T22:01:00+01:00
Times with new Time Zone Set
Date 1: 2019-12-21T22:01:00+01:00
Date 2: 2019-12-21T21:01:00+00:00
Date 3: 2019-12-21T21:01:00+00:00
The difference lies in the output of the second date. The time is off by one hour for the UTC time (22:01:00 instead of 21:01:00).
I am at a loss here. I tried to set a default time zone within php.ini, to no avail.
Using "date" and "date -u" gives me the correct times.
timedatectl gives me the following output: Local time: Sa 2019-12-21 22:06:49 CEST Universal time: Sa 2019-12-21 21:06:49 UTC Time zone: Europe/Berlin (CET, +0100)
Maybe someone else has an idea what is going on here.