简体   繁体   English

如何在PHP中将2014-06-24T22:33:49.180Z格式转换为Ymd H:i:s

[英]How to convert 2014-06-24T22:33:49.180Z format into Y-m-d H:i:s in PHP

I received Fatal error: Call to a member function format() on a non-object error when I tried to use format on a json converted date string of 2014-06-24T22:37:13.151Z (specifically from new Date() ) 我收到Fatal error: Call to a member function format() on a non-object当我尝试在2014-06-24T22:37:13.151Z的json转换日期字符串上使用格式时(特别是来自new Date()Fatal error: Call to a member function format() on a non-object错误Fatal error: Call to a member function format() on a non-object

$objData->myCodeCreateDate="2014-06-24T22:39:34.652Z"
$date = DateTime::createFromFormat('j-M-Y', $objData->myCodeCreateDate);
echo $date->format('Y-m-d H:i:s');

That looks like the way Amazon sends back its timestamp, which follows this format in UTC time: 看起来像亚马逊发回其时间戳的方式,该时间戳遵循UTC时间的这种格式:

Ymd\\TH:i:su\\Z . Ymd\\TH:i:su\\Z

You can edit your createFromFormat format to the above, and it should work. 您可以将createFromFormat格式编辑为上述格式,并且该格式应该可以使用。

Here's an example with your data: 这是您的数据的示例:

$date_string = "2014-06-24T22:37:13.151Z";
$date_object = DateTime::createFromFormat('Y-m-d\TH:i:s.u\Z', $date_string);
echo $date_object->format('Y-m-d H:i:s');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Carbon 在 laravel 中将日期(2020-11-23T13:26:02.000Z)格式化为 Ymd h:i:s? - How to format Date (2020-11-23T13:26:02.000Z) to Y-m-d h:i:s in laravel using Carbon? PHP未来日期(Ymd H:i:s) - PHP Future Date (Y-m-d H:i:s) 我需要转换PHP日期('Ymd H:i:s P'); asp经典 - I need to convert PHP date('Y-m-d H:i:s P'); to asp classic 从 php 日期获取日期格式,如“Ymd H:i:s” - Get date format like “Y-m-d H:i:s” from a php date 如何以Ymd H:i:s格式在ORACLE中保存日期? - How to save date in ORACLE in Y-m-d H:i:s format? 如何使用日期('Ymd H:i:s'); 函数值作为列名在PHP? - how to use date('Y-m-d H:i:s'); function value as column name in php? PHP:时区调整功能计算Ymd H:i:s的方式与Ymd不同 - PHP: Timezone adjustment function calculates Y-m-d H:i:s differently than Y-m-d 将两个日期作为字符串与格式 (Ymd h:i:s) 进行比较与在 php 中将两个日期与日期的 strtotime 进行比较有什么区别? - What is the difference between compare two date as string with format (Y-m-d h:i:s) and two date with strtotime of date in php? 从“Ymd H:i:s”格式的日期数组中获取最新日期 - Get most recent date from an array of dates in "Y-m-d H:i:s" format 用strtotime格式化'Ymd H:i:s' - Formatting 'Y-m-d H:i:s' with strtotime
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM