好的,我有以下代码
$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 时区(我使用的是美国/温哥华),但它给了我一个奇怪的结果
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
我哪里出错了?