如何2015-06-05 14:05:01使用PHP 将时间戳转换为另一个时区?
我已经阅读并尝试了很多方法,但我无法得到理想的结果.使用date_format($date,"M d h:i A")和date_default_timezone_set('America/New_York')我得到June 05 2:05 PM哪个是服务器时区的原始来源并且正确.
我需要的是2015-06-05 14:05:01使用例如转换date_default_timezone_set('America/Los_Angeles')并date_format($date,"M d h:i A")获得结果June 05 11:05 AM.
// Create the DateTime() object and set the timezone to 'America/New_York'
$date = new DateTime('2015-06-05 14:05:01', new DateTimeZone('America/New_York'));
// Change the timezone to 'America/Los_Angeles'
$date->setTimezone(new DateTimeZone('America/Los_Angeles'));
// Print out the date and time in the new timezone
echo $date->format('M d h:i A');
Run Code Online (Sandbox Code Playgroud)
易于阅读,使其易于保持.