Php 将日期时间转换为GMT+;#格式转换为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
$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);