Gui*_*dre 6 php symfony1 date symfony-1.4
我想在Symfony 1.4中更改日期的格式
默认的是:
<?php echo $question->getUpdatedAt();
// Returns 2010-01-26 16:23:53
?>
Run Code Online (Sandbox Code Playgroud)
我希望我的日期格式如下: 26/01/2010 - 16h23
我尝试使用format_date辅助DateHelper类.
不幸的是,API相当空(关于它真的需要做些什么.)
浏览帮助器的源代码,我发现可以传递第二个参数format.
我假设它使用与PHP的日期函数相同的语法.但这是它输出的内容(与上面相同):
<?php sfContext::getInstance()->getConfiguration()->loadHelpers('Date');
// [...]
echo format_date($question->getUpdatedAt(),'d/m/y - H\hi')
// Returns 26/23/2010 - 16\4i
Run Code Online (Sandbox Code Playgroud)
我敢肯定,我不是第一个在这方面遇到麻烦的人,但我一直在谷歌上搜索,没有任何准确的信息显示出来.
你们有没有想过如何在Symfony 1.4中格式化日期?
Fel*_*ing 14
你可以做:
$question->getDateTimeObject('updated_at')->format('d.m.Y');
// I assume the field's name is 'updated_at'
Run Code Online (Sandbox Code Playgroud)
来自文档:
日期设定者和吸气剂
我们添加了两个用于检索Doctrine日期或时间戳值的新方法作为PHP DateTime对象实例.
Run Code Online (Sandbox Code Playgroud)echo $article->getDateTimeObject('created_at')->format('m/d/Y');您还可以通过调用setDateTimeObject方法并传递有效的DateTime实例来设置日期值.
Run Code Online (Sandbox Code Playgroud)$article->setDateTimeObject('created_at', new DateTime('09/01/1985'));
但它似乎只适用于Doctrine.