Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 2012-03-19T22:10:56.000Z至2013年11月13日星期三18:06:37+0000的秘密日期格式_Php_Date - Fatal编程技术网

Php 2012-03-19T22:10:56.000Z至2013年11月13日星期三18:06:37+0000的秘密日期格式

Php 2012-03-19T22:10:56.000Z至2013年11月13日星期三18:06:37+0000的秘密日期格式,php,date,Php,Date,如何将日期格式从2012-03-19T22:10:56.000Z转换为Wed Nov 13 18:06:37+0000 2013,而不使用substr等字符串函数。Gnip正在使用此日期格式。不知道是什么格式 我试着使用date函数 $postedTime = "2012-03-19T22:10:56.000Z"; date($postedTime,"D M d H:i:s O Y"); 但是我得到一个错误,因为$postedTime是一个字符串,不是长变量。您需要在日期函数中交换顺序 da

如何将日期格式从2012-03-19T22:10:56.000Z转换为Wed Nov 13 18:06:37+0000 2013,而不使用substr等字符串函数。Gnip正在使用此日期格式。不知道是什么格式

我试着使用date函数

$postedTime = "2012-03-19T22:10:56.000Z";
date($postedTime,"D M d H:i:s O Y"); 

但是我得到一个错误,因为$postedTime是一个字符串,不是长变量。

您需要在日期函数中交换顺序

date('format string', $time)
所以你想要:

date("D M d H:i:s O Y", strtotime($postedTime)); 

您需要在日期函数中交换订单

date('format string', $time)
所以你想要:

date("D M d H:i:s O Y", strtotime($postedTime)); 

如果可以使用专门为处理日期而设计的函数,为什么要使用substr

$date = new DateTime('2012-03-19T22:10:56.000Z');
echo $date->format('r Y');

如果可以使用专门为处理日期而设计的函数,为什么要使用substr

$date = new DateTime('2012-03-19T22:10:56.000Z');
echo $date->format('r Y');

可以使用转换DateTime对象中的字符串

$date = new DateTime($postedTime);
然后您可能需要更改时区,因为您的postedTime是Zulu的时区Z

$date->setTimezone(new DateTimeZone('Europe/Rome'));
也可以加上或减去一个合适的偏移日期间隔

最后,如果需要在date中使用时间戳,可以使用[getTimeStamp][1]

如果您在Zulu中拥有所有日期时间,只需使用

$date = new DateTime($postedTime);
date("Y-m-d H:i:s", $date->getTimeStamp());
或者如果您不需要时间戳

$date = new DateTime($postedTime);
print $date->format('Y-m-d H:i:s');

您应该得到与您输入的日期相同的日期。如果偏移一个或多个小时加上或减去,则有。

可以使用

$date = new DateTime($postedTime);
然后您可能需要更改时区,因为您的postedTime是Zulu的时区Z

$date->setTimezone(new DateTimeZone('Europe/Rome'));
也可以加上或减去一个合适的偏移日期间隔

最后,如果需要在date中使用时间戳,可以使用[getTimeStamp][1]

如果您在Zulu中拥有所有日期时间,只需使用

$date = new DateTime($postedTime);
date("Y-m-d H:i:s", $date->getTimeStamp());
或者如果您不需要时间戳

$date = new DateTime($postedTime);
print $date->format('Y-m-d H:i:s');

您应该得到与您输入的日期相同的日期。如果它被一个或多个小时的加减抵消,那么您已经完成了。

谢谢您的工作。虽然我更改了格式$date=new DateTime'2012-03-19T22:10:56.000Z';echo$date->formattd M d H:i:s O Y;谢谢你的工作。虽然我更改了格式$date=new DateTime'2012-03-19T22:10:56.000Z';echo$date->formattd M d H:i:s O Y;