Using the DATE function in PHP to format the timestamp, you can use Date_format to implement the Smarty
Specific usage:
The code is as follows |
Copy Code |
{$timestamp |date_fomat: "%y-%m-%d%h:%m:%s"} |
Note: | No spaces on either side
Output form: 2010-07-10 16:30:25
Other uses are as follows:
The code is as follows |
Copy Code |
{$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"} |
instance
date_format[Date format]
index.php:
The code is as follows |
Copy Code |
$smarty = new Smarty; $smarty->assign (' Yesterday ', Strtotime ('-1 day ')); $smarty->display (' Index.tpl '); |
INDEX.TPL:
The code is as follows |
Copy Code |
{$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"} |
OUTPUT:
The code is as follows |
Copy Code |
Feb 6, 2001 Tuesday, February 6, 2001 14:33:00 Feb 5, 2001 Monday, February 5, 2001 14:33:00 |
Smarty's date_format can't be solved in Chinese.
{$smarty. Now|date_format: "%y year%m Month%d days"} This is the "2010%m Month%d days" + some garbled if the Chinese character is added to the sky after the normal, but the output also has a space.
To solve this problem, read the Smarty plug-in code modifier.date_format.php:
Found inside strftime This PHP function is not good for Chinese support.
So I modified the modifier.date_format.php function, once and for all. You can copy and replace the original content directly.
And I still support Simplified Chinese in this function.
The code is as follows |
Copy Code |
function Smarty_modifier_date_format ($string, $format = '%b%e,%Y ', $default _date = ') { if (substr (php_os,0,3) = = ' WIN ') { $_win_from = Array ('%e ', '%T ', '%d '); $_win_to = Array ('% #d ', '%h:%m:%s ', '%m/%d/%y '); $format = Str_replace ($_win_from, $_win_to, $format); } $arrTemp = Array (' Year ', ' Month ', ' Day ', ' time ', ' minute ', ' second ', '? R '); foreach ($arrTemp as $v) { if (Strpos ($format, $v)) { $strFormat = str_replace ('% ', ', $format); } } if ($string!= ') { if (!emptyempty ($strFormat)) return date ($strFormat, Smarty_make_timestamp ($string)); else return strftime ($format, Smarty_make_timestamp ($string)); } elseif (Isset ($default _date) && $default _date!= ') { if (!emptyempty ($strFormat)) return date ($strFormat, Smarty_make_timestamp ($default _date)); else return strftime ($format, Smarty_make_timestamp ($default _date)); } else { Return }
} |