Get dates in "human readable" format

282 views Asked by At

I am working in a RESTFul API using Symfony2 and FOSRestBundle. The entities use Gedmo for Timestampable options:

use Gedmo\Timestampable\Traits\TimestampableEntity;

And I get the createdAt as any other column:

$obj->getCreatedAt()

Then I pass that response to FOSRestBundle:

 $respEmail = [
        "id"                 => (string)$entEmail->getId(),
        ...
        "category"           => $entEmail->getEmailsCategory(),
        "createdAt"          => $entEmail->getCreatedAt()
 ];

 $view->setData($respEmail)->setStatusCode(200);

And I get this:

{
  "id": "5",
  ...
  "category": "sent",
  "createdAt": "2015-06-12T11:00:55-0430"
}

How do I fix the date? I want something like 2015-06-12 11:00:55. Any help?

1

There are 1 answers

0
Darragh Enright On BEST ANSWER

If it's a DateTime() object, and I assume it is, you should be able to do:

$entEmail->getCreatedAt()->format('Y-m-d H:i:s')

More information on DateTime::format()