好的,我有以下代码:
$from = "Asia/Manila";
$to = "UTC";
$org_time = new DateTime("2012-05-15 10:50:00");
$org_time = $org_time->format("Y-m-d H:i:s");
$conv_time = NULL;
$userTimezone = new DateTimeZone($from);
$gmtTimezone = new DateTimeZone($to);
$myDateTime = new DateTime($org_time, $gmtTimezone);
$offset = $userTimezone->getOffset($myDateTime);
$conv_time = date('Y-m-d H:i:s', $myDateTime->format('U') + $offset);
echo $conv_time;
使用这段代码,我想将
2012-05-15 10:50:00
转换为UTC和-8时区(我使用的是America/Vancouver),但它给我奇怪的结果。
Asia/Manila > UTC
2012-05-15 19:50:00 = the correct is 2012-05-15 02:50
并且针对美国/温哥华地区
Asia/Manila > America/Vancouver
2012-05-16 02:50:00 = the correct is 2012-05-14 19:50
我做错了什么?