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

4
我有一个输入格式,需要将其转换为GMT格式:
$input = array(
           "gmt" => "+7",
           "datetime" => "2017-10-10 12:10:12"
         );

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


我认为你想了解本地化方面的内容 https://dev59.com/uGTWa4cB1Zd3GeqPG8-z - StuiterSlurf
2个回答

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

0

单拍(不建议使用):

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接