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

Convert datetime in GMT+# format to GMT

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

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

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

试试这个:

$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');

一次性(不推荐):

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