簡體   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