亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

使用Smarty 獲取當前日期時間和格式化日期時間的方法詳解

 更新時間:2013年06月18日 12:20:04   作者:  
本篇文章是對使用Smarty獲取當前日期時間和格式化日期時間的方法進行了詳細的分析介紹,需要的朋友參考下

在Smarty 中獲取當前日期時間和格式化日期時間與PHP中有些不同的地方,這里就為您詳細介紹:

首先是獲取當前的日期時間:
在PHP中我們會使用date函數(shù)來獲取當前的時間,實例代碼如下:
date("Y-m-dH:i:s");   //該結(jié)果會顯示為:2010-07-27 21:19:36 的模式

但是在Smarty 模板中我們就不能使用date 了,而是應(yīng)該使用 now 來獲取當前的時間,實例代碼如下:
{$smarty.now}      //該結(jié)果會顯示為:1280236776的時間戳模式

然而我們還可以將這個時間戳格式化,實例代碼如下:
{$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'}   //該結(jié)果會顯示為 2010-07-27 21:19:36 的時間模式

需要說明的是 Smarty 中的這個date_format 時間格式化函數(shù)和PHP中的 strftime()函數(shù)基本上相同,您可以去查看PHP中的 strftime() 函數(shù)中的format 識別轉(zhuǎn)換標記。其中 %Y 是代表十進制年份,%m是代表十進制月份,%d 是代表十進制天數(shù),%H 是代表十進制小時數(shù),%M是代表十進制的分數(shù),%S是代表十進制的秒數(shù)(這里的S是大寫的哦)。
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
smarty中date_format函數(shù)用法
在php中使用date函數(shù)來格式化時間戳,smarty中可以使用date_format來實現(xiàn)
具體用法:{$timestamp|date_fomat:”%Y-%m-%d %H:%M:%S”} 注意:| 兩邊沒有空格
輸出形式:2010-07-10 16:30:25
其他用法如下:
{$smarty.now|date_format}
{$smarty.now|date_format:”%A, %B %e, %Y”}
{$smarty.now|date_format:”%H:%M:%S”}
{$yesterday|date_format}
{$yesterday|date_format:”%A, %B %e, %Y”}
{$yesterday|date_format:”%H:%M:%S”}

eg:

在模板頁用
{$goods.add_time|date_format:"%Y-%m-%d %H:%M:%S"}
--------------------------
index.php:

$smarty = new Smarty;
$smarty->assign('currtime', time());
$smarty->display('index.tpl');

index.tpl:

{$smarty.now|date_format}//格式化當前時間
{$smarty.now|date_format:"%H:%M:%S"}
{$currtime|date_format}//格式化傳過來的時間
{$currtime|date_format:"%A, %B %e, %Y"}
{$currtime|date_format:":"%Y-%m-%d %H:%M:%S"}

OUTPUT://以上輸出以下結(jié)果

Dec 26, 2008
08:55:25
Dec 26, 2008
Friday, December 26, 2008
2008-08-26 08:55:21

相關(guān)文章

最新評論