Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将日期时间转换为GMT+;#格式转换为GMT_Php_Datetime_Gmt - Fatal编程技术网

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

Php 将日期时间转换为GMT+;#格式转换为GMT,php,datetime,gmt,Php,Datetime,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", "dateti

我有这样的输入格式,我需要将其转换为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);