I tend to have to do timezone conversions quite a bit in my line of work. It seems like every time I to process timezones I need I have to search and I tend to come up with a different solution in PHP each time. Well i decided to post this solution on my blog so i’ll have one consistent way of doing it.

This method is pretty easy with PHP 5 and it taken directly from the php.net reference manual.

$date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru'));
echo $date->format('Y-m-d H:i:sP') . "\n";

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

Here is the expected output

2000-01-01 00:00:00+12:00
2000-01-01 01:45:00+13:45