Fabio Santos Fabio Santos - 3 months ago 34
PHP Question

laravel 5 format datetime

I have an array that return the following date time:

$item['created_at'] => "2015-10-28 19:18:44"


And I need this outuput:

"2016-08-10T13:15:00.000+10:00"


Exist any function to convert this date?

Answer

Try this:

$dt = new \DateTime('2015-10-28 19:18:44', new \DateTimeZone('Europe/London'));
dd($dt->format('c')); // string '2015-10-28T19:18:44+00:00' (length=25)

Alternatively take a look at Carbon

Comments