How to Convert an Existing PHP DateTime Object From One Time Zone to Another?

If you have an already instantiated DateTime object, then you can change its time zone by calling the DateTime::setTimezone() method, for example, in the following way:

$existingDateTime->setTimezone(new DateTimeZone('Europe/Berlin'));

For example, consider the following DateTime object that's instantiated with a time zone set to 'Europe/London', but is later changed to 'Europe/Berlin' by using the DateTime::setTimezone() method:

$dt = new new DateTime('now', new DateTimeZone('Europe/London'));
// ...
$dt->setTimezone(new DateTimeZone('Europe/Berlin'));
// ...

You can get the list of supported time zones from the official PHP documentation.


Hope you found this post useful. It was published (and was last revised ). Please show your love and support by sharing this post.