Date 在indexSuccess.php中设置日期格式
我想将Date 在indexSuccess.php中设置日期格式,date,symfony1,format,symfony-1.4,Date,Symfony1,Format,Symfony 1.4,我想将created_在字段日期的格式设置为2011年5月3日,以显示在indexSuccess.php和showsucture.php 你能帮我吗? 谢谢我相信日期是以字符串格式返回的Y-m-d H:I:s,这与MySQL的datetime类型相符。假设您使用的是PHP>5.3,最好使用将其转换为PHPDateTime实例 因此,在控制器中: $this->creation_date = DateTime::createFromFormat('Y-m-d H:i:s', $item-&g
created_在
字段日期的格式设置为2011年5月3日,以显示在indexSuccess.php
和showsucture.php
你能帮我吗?
谢谢我相信日期是以字符串格式返回的
Y-m-d H:I:s
,这与MySQL的datetime类型相符。假设您使用的是PHP>5.3,最好使用将其转换为PHPDateTime
实例
因此,在控制器中:
$this->creation_date = DateTime::createFromFormat('Y-m-d H:i:s', $item->created_at);
那么,在你看来:
<?php echo $creation_date->format('d.F.Y') ?>
并且认为:
<?php echo date('d.F.Y', $creation_date) ?>
您可以在indexSuccess.php和showSuccess.php中使用symfony,而不是例如:
<?php $value->getCreatedAt() ?>
下一步:
您可以使用格式。某些数据的格式绝对不属于控制器上下文-因此请使用
use_helper("date");
echo format_date($myDate);
从模板(showsucture.php、blaSuccess.php)或部分(form.php、list.php、test.php)中的symfony的日期帮助器
您可以在此处或源文件中找到更多信息。要创建类似您的示例(2011年5月3日)的日期字符串,请使用以下方法:
<?php use_helper("date"); ?>
<?php echo format_date($myDate,'dd. MMM. yyyy'); ?>
你写的第一行代码应该放在哪里?我是symfony的新手。。。仍然不知道symfony创建的所有文件。顺便说一句,谢谢:)控制器将是actions.class.php
,在您模块的actions
文件夹中。我将executeIndex
函数的第一行放在action.class.php
中,它得到以下错误:致命错误:调用未定义的方法DateTime::createfromformat()在第18行的C:\wamp\www\sgps\apps\frontend\modules\breves\actions\actions.class.php中
@Eva OK,所以您必须使用PHP5.2。那样的话,请看我的编辑。非常感谢。因此,如果我有以下代码:
我应该编写使用助手(“日期”)回送格式\u date($sgps\u breves->getCreatedAt())
?
use_helper("date");
echo format_date($myDate);
<?php use_helper("date"); ?>
<?php echo format_date($myDate,'dd. MMM. yyyy'); ?>