確定我有這個以下代碼在PHP轉換時間字符串到不同的時區
$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
我哪裏出錯了?
是的,謝謝你,對不起,我試圖在困難的方式自己做事情 –