加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 将GMT#格式的datetime转换为GMT

发布时间:2020-12-13 16:09:55 所属栏目:PHP教程 来源:网络整理
导读:我有这样的输入格式,我需要将其转换为GMT格式: $input = array( "gmt" = "+7","datetime" = "2017-10-10 12:10:12" ); 输入数据包含gmt数组索引,它显示哪个gmt格式,日期时间索引显示需要从GMT 7转换为GMT的“Y-m-d h:i:s”中的日期. 解决方法 试试这个:
我有这样的输入格式,我需要将其转换为GMT格式:

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

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

解决方法

试试这个:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读