Php 将日期时间如 “2017-01-10T18:00:00.000Z” 转换为标准时间

2022-08-30 22:43:26

我从其他服务器收到回复,日期时间如下,

"2017-01-10T18:00:00.000Z"

我想像这样将其转换为标准日期时间,我该怎么做?

"2017-01-10 18:00:00"

有没有一种标准的方法可以做到这一点?还是我依靠正则表达式来解码它?

注意:

大多数人建议我使用下面的功能

echo date("Y-m-d H:i:s", strtotime("2017-01-10T18:00:00.000Z")) . "\n";**

但是输出我得到的这个函数是错误的是“2017-01-11 05:00:00”而不是“2017-01-11 18:00:00”为什么?我想像我说的“2017-01-10 18:00:00”


答案 1

你可以使用
希望它能帮助你:)date('Y-m-d h:i:s', strtotime($yourDate));


答案 2

啊,好吧。。。在php中,以Z结尾的长时间戳可以转换为带有strototime的unix时间戳,然后使用date函数返回日期

echo date("Y-m-d H:i:s", strtotime("2017-01-10T18:00:00.000Z")) . "\n";

警告:服务器上的当前时区设置可能会导致时间调整


推荐