How to Convert Date and Time from One Time Zone to Another in PHP

It’s really simple to convert a DateTime from one time zone to another in PHP. Just create a DateTime object using date & time to be converted as the first parameter and the original time zone as the second parameter. Then change the time zone to the desired one using the setTimezone method. That’s all!

$date = new DateTime('2018-04-11 12:00:00', new DateTimeZone('Europe/London'));
echo $date->format('Y-m-d H:i:sP') . "\n";

$date->setTimezone(new DateTimeZone('Europe/Bucharest'));
echo $date->format('Y-m-d H:i:sP') . "\n";

The above will output:

2018-04-11 12:00:00+01:00
2018-04-11 14:00:00+03:00

Leave a Reply

Your email address will not be published. Required fields are marked *