Jo Smo Jo Smo - 1 year ago 94
PHP Question

Convert UTC datetime to another timezone

How can i convert a date like this:

2012-07-16 01:00:00 +00
(it's in the
UTC +00:00
timezone) to
UTC +04:00
timezone in PHP? Ensuring that daylight saving will be correctly handelled?

Answer Source

Use DateTime and DateTimeZone.

$date = new DateTime('2012-07-16 01:00:00 +00');
$date->setTimezone(new DateTimeZone('Europe/Moscow')); // +04

echo $date->format('Y-m-d H:i:s'); // 2012-07-15 05:00:00 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download