Reputation: 8593
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()
)
$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');
Upvotes: 0
Views: 2776
Reputation: 5382
That looks like the way Amazon sends back its timestamp, which follows this format in UTC time:
Y-m-d\TH:i:s.u\Z
.
You can edit your createFromFormat
format to the above, and it should work.
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');
Upvotes: 4