我想将任何时区转换为UTC我正在编写下面的代码,但它不起作用,它给同一时间不转换为UTC可以任何人帮助我。
$triggerOn = '04/01/2013 03:08 PM';
$user_tz = 'GMT';
echo $triggerOn;
$schedule_date = new DateTime($triggerOn, new DateTimeZone($user_tz));
$schedule_date->setTimeZone(new DateTimeZone('UTC'));
$triggerOn = $schedule_date->format('Y-m-d H:i:s');
echo $triggerOn;
答案 0 :(得分:1)
试试这个:
$triggerOn = '04/01/2013 03:08 PM';
echo gmdate('Y-m-d H:i:s',strtotime($triggerOn));
答案 1 :(得分:1)
$triggerOn = '04/01/2013 03:08 PM';
$newdate = new DateTime($triggerOn);
$newdate->setTimezone(new DateTimeZone("UTC"));
echo $newdate->format("Y-m-d H:i:s e") . "\n";