将GMT +#格式的日期时间转换为GMT

时间:2017-11-01 07:13:55

标签: php datetime gmt

我有这样的输入格式,我需要将其转换为GMT格式:

$input = array(
           "gmt" => "+7",
           "datetime" => "2017-10-10 12:10:12"
         );

输入数据包含gmt数组索引,该索引显示哪个gmt格式,日期时间索引显示需要从GMT + 7转换为GMT的“Y-m-d h:i:s”中的日期。

2 个答案:

答案 0 :(得分:1)

试试这个:

$input = array(
  "gmt" => "+7",
  "datetime" => "2017-10-10 12:10:12"
);

$ny = new DateTimeZone("GMT+7");
$gmt = new DateTimeZone("GMT");
$date = new DateTime( $input["datetime"], $ny );
$date->setTimezone( $gmt );

echo $date->format('Y-m-d H:i:s');

答案 1 :(得分:0)

Oneshot(不推荐):

echo date('Y-m-d h:i:s', strtotime($input['datetime'])+$input['gmt']*3600);
相关问题