繁体   English   中英

在cakephp中格式化日期字符串

[英]formatting date string in cakephp

我是cakephp的新手,我有一个简单的用户控制器,对应一个用户表。 我在表中创建了一个字段,我希望使用niceShort()函数输出视图操作。 我如何在视图中使用它?

目前的代码是:

<p>Member since <?php echo $user['User']['created']?></p>

谢谢,

Jonesy

在控制器中,您可以包含构建时间助手:

users_controllee.php:

var $helpers = array('Time');

在视图中:

<p>Member since <?php echo $time->niceShort($user['User']['created']); ?></p>

我认为darko是对的。

您可以使用PHP函数date()以任何类型格式化日期。

示例:

$date = date("Ymd H:i:s", strtotime($user['User']['created']));

这里,strtotime()是cakePHP以datetime格式转换的函数。

现在,您将拥有$ date变量,其日期格式为'YYYY-mm-dd Hour:Minute:Second'。

有关更多选项,请参阅PHP日期手册: http//php.net/manual/en/function.date.php

希望这会对你有所帮助......

只需使用内置的php函数日期。

你可以像这样使用它:

echo date('d.m.Y', strtotime($user['User']['created']));

您可以根据构建模式使用您喜欢的任何格式进行日期格式化。

http://php.net/manual/en/function.date.php

作为参考点,TimeHelper是CakePHP有很多值得关注的好东西http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM