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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41561371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:24:56  来源:igfitidea点击:

Php Convert date time like "2017-01-10T18:00:00.000Z" to standard time

phpdate

提问by mahen3d

I get a response from a other server with a date time like below,

我收到来自其他服务器的响应,其日期时间如下所示,

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

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

I want to convert this to standard date time like this, how do i do this ?

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

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

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

is there a standard way of doing this ? or do i have rely on the regular expressions to the decode it ?

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

NOTE:

笔记:

most people suggest i use below function

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

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

but output i get is wrong from this function is "2017-01-11 05:00:00" not as "2017-01-11 18:00:00" why ? I want as i said "2017-01-10 18:00:00"

但是我从这个函数得到的输出是“2017-01-11 05:00:00”而不是“2017-01-11 18:00:00”,为什么?我想要正如我所说的“2017-01-10 18:00:00”

回答by Amit Sahu

you can use date('Y-m-d h:i:s', strtotime($yourDate));
Hope it will help you :)

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

回答by S. Imp

Ah OK...in php, that long timestamp ending with Z can be converted to a unix timestamp with strototime and then back to a date using the date function

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

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

WARNING: the current time zone setting on your server may result in the time being adjusted

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

回答by Marprin

You can use the date_time() function from php.

您可以使用 php 中的 date_time() 函数。

You should take a look on this link for solving your problem.

您应该查看此链接以解决您的问题。

PHP Convert ISO date to more readable format?

PHP 将 ISO 日期转换为更易读的格式?