Get the current date time and format date time in smarty with some different places in PHP, here is a detailed description:
The first is to get the current date time:
In PHP we use the DATE function to get the current time, and the instance code is as follows:
Date ("Y-m-dh:i:s"); The results will appear as follows: the 2010-07-27 21:19:36 model
But instead of using date in the Smarty template, we should use now to get the current time, with the instance code as follows:
{$smarty. Now}//The result will be displayed as: 1280236776 timestamp mode
However, we can also format the timestamp with the instance code as follows:
{$smarty. Now|date_format: '%y-%m-%d%h:%m:%s '}//The result will be displayed as the time pattern for the 2010-07-27 21:19:36
It should be explained that this Date_format time format function in Smarty is essentially the same as the strftime () function in PHP, and you can see the format recognition conversion tag in the strftime () function in PHP. Where%Y is representing the decimal year,%m is the decimal month,%d is the decimal days,%H is the decimal hour,%m is the decimal point, and%s is the number of seconds on behalf of the decimal (the S is capitalized here).
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////
date_format function usage in Smarty
Using the DATE function in PHP to format the timestamp, you can use Date_format to implement the Smarty
Specific usage:{$timestamp |date_fomat: "%y-%m-%d%h:%m:%s"} Note: | There is no space on either side
Output form: 2010-07-10 16:30:25
Other uses are as follows:
{$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
In the template page, use
{$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}//format the current time
{$smarty. Now|date_format: "%h:%m:%s"}
{$currtime |date_format}//format passed in time
{$currtime |date_format: "%A,%B%e,%Y"}
{$currtime |date_format: ":%y-%m-%d%h:%m:%s"}
output://above output the following results
Dec 26, 2008
08:55:25
Dec 26, 2008
Friday, December 26, 2008
2008-08-26 08:55:21