From a DateTime object, I am interested in getting the time in different TimeZones. As explained in the DateTime::setTimezone doc, this works pretty well when the DateTime object is created from a string:
$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";
$date->setTimezone(new DateTimeZone('UTC'));
echo $date->format('Y-m-d H:i:sP') . "\n";
echo $date->getTimestamp() . "\n";
The above examples will output:
2000-01-01 00:00:00+12:00
2000-01-01 01:45:00+13:45
1999-12-31 12:00:00+00:00
946641600
Now is the interesting part: If we pick up our timestamp, and initiate our DateTime Object with it following the manual instructions.
$date2 = new DateTime('@946641600');
$date2->setTimezone(new DateTimeZone('Pacific/Nauru'));
echo $date2->format('Y-m-d H:i:sP') . "\n";
$date2->setTimezone(new DateTimeZone('Pacific/Chatham'));
echo $date2->format('Y-m-d H:i:sP') . "\n";
$date2->setTimezone(new DateTimeZone('UTC'));
echo $date2->format('Y-m-d H:i:sP') . "\n";
echo $date2->getTimestamp() . "\n";
And here we get: // [edit] humm... Sorry, this output is wrong...
1999-12-31 12:00:00+00:00
1999-12-31 12:00:00+00:00
1999-12-31 12:00:00+00:00
946641600
UTC forever !!! We cannot change the timezone anymore !?!
Is it PHP or is it me ? Version 5.3.15