How to format a getUpdatedAt() kind of date in Symfony?

孤人 提交于 2019-12-03 14:29:29

Have a look at the new functions in 1.4.

You can do:

$question->getDateTimeObject('updated_at')->format('d.m.Y');
// I assume the field's name is 'updated_at'

From the docs:

Date Setters and Getters

We've added two new methods for retrieving Doctrine date or timestamp values as PHP DateTime object instances.

echo $article->getDateTimeObject('created_at')->format('m/d/Y');

You can also set a dates value by simply calling the setDateTimeObject method and passing a valid DateTime instance.

$article->setDateTimeObject('created_at', new DateTime('09/01/1985'));

But it seems only to work for Doctrine.

How bout going with the default PHP date function? date('d/m/Y', strtotime($question->getUpdatedAt())

You can use also sfDateFormat class to work with dates. link text

jaycreation

do you try :

echo $question->getUpdatedAt('d/m/y - H\hi')

I think it's the easiest way

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!