获取 "human readable" 格式的日期

Get dates in "human readable" format

我正在使用 Symfony2 和 FOSRestBundle 在 RESTFul API 中工作。这些实体将 Gedmo 用于时间戳选项:

use Gedmo\Timestampable\Traits\TimestampableEntity;

我得到的 createdAt 与任何其他列一样:

$obj->getCreatedAt()

然后我将该响应传递给 FOSRestBundle:

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

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

我明白了:

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

如何确定日期?我想要 2015-06-12 11:00:55 这样的东西。有帮助吗?

如果它是一个 DateTime() 对象,我认为它是,你应该能够做到:

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

有关 DateTime::format()

的更多信息