The example of this article describes the Smarty date-time operation method. Share to everyone for your reference, specific as follows:
$smarty = new Smarty;
$smarty->assign (' Yesterday ', Strtotime ('-1 day '));
$smarty->display (' Index.tpl ');
INDEX.TPL:
{$smarty. Now|date_format}//sep 7, 2009
{$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"}
Smarty Display format Current date
{$smarty. Now|date_format}
{$smarty. Now|date_format: "%A,%m%e,%Y"}
{$smarty. Now|date_format: "%h:%m:%s"}
Smarty Symbol Description
%y represents year
%m represents the Month
%d indicates day
%A said the day of the week,
%H means hours
%m represents minutes
%s represents seconds
If the date is a variable, you can:
{$yesterday |date_format: "%A,%B%e,%Y"}
{$yesterday |date_format: "%h:%m:%s"}
Smarty Internal Date function html_select_date () use instructions
Prefix |
The string type default prefix is named "Date_ |
Start_year |
The string type defaults to that the current year can still be represented in (+/-n) mode as start_year= " -10" option is starting from 1999 |
End_year |
String type default ibid (+/-n) mode indicates that end_year= "+5" option is up to 2014 |
Field_order |
String type default Mdy a select in the order of the Year of the month |
Month_format |
The string type default%b is displayed as January, February, etc.%b format shows the first three letters of the month in short form the month for the number display |
Day_format |
String type default%02d numeric representation from 01~31 and is not associated with the month%b format is rarely used in binary display formats |
Additional properties:
Display_days |
Boolean type controls whether day's select is displayed |
Display_months |
Boolean type controls whether the month select is displayed |
Display_years |
Boolean type controls whether the year's select is displayed |
Year_as_text |
Boolean type true displays as text year false as Drop-down menu type |
Reverse_years |
The year is displayed in reverse order when the Boolean type True |
Year_size |
String type values are drop-down menu-type output 0 or 1 o'clock for up and down arrows with greater than 1 control |
Month_size |
Ditto |
Day_size |
Ditto |
Examples are as follows:
{html_select_date prefix= "StartDate" time= $time start_year= "-5" end_year= "+1" Display_days=false}
OUTPUT: (2009)
<select name= "Startdatemonth" > <option value= "1" >January</option> <option value= "2" >
February</option> <option value= "3" >March</option> <option value= "4" >April</option> <option value= "5" >May</option> <option value= "6" >June</option> <option value= "7" >july </option> <option value= "8" >August</option> <option value= "9" >September</option> < Option value= "Ten" >October</option> <option value= "One" >November</option> <option value= "12" selected>december</option> </select> <select name= "Startdateyear" > <option value= "1999" >
1995</option> <option value= "1999" >1996</option> <option value= "1999" >1997</option> <option value= "1999" >1998</option> <option value= "1999" >1999</option> <option value= " Selected>2000</option> <option value= "2001" >2001</option> </sElect>
Other properties, please debug yourself. The disadvantage of this date processing function is that day is not associated with month, and it is better to use JS processing
One of the functions that JS displays day can be defined as follows:
function Showdays (year,month) {
var day= "Day";
if (month.value==0) {
document.getElementById (day). Length=1;
return;
} else{
if (month.value==1| | month.value==3| | month.value==5| | month.value==7| | month.value==8| |month.value==10| | month.value==12) {
document.getElementById (day). Length=1;
CreateList (1,32,day);
return;
} else if (month.value==2) {
if (year.value%4==0&&year.value%100!=0| | year.value%400==0) {
document.getElementById (day). Length=1;
CreateList (1,30,day);
return;
} else{
document.getElementById (day) length=1;
CreateList (1,29,day);
return;
}
else{
document.getElementById (day) length=1;
CreateList (1,31,day);
return;}}
More interested in smarty related content readers can view the site topics: "Smarty Template Primer Tutorial", "PHP Template Technology Summary", "PHP based on PDO Operation Database Skills summary", "PHP Operations and Operator Usage Summary", "PHP Network Programming Skills Summary", " Introduction to PHP Basic Grammar, "Introduction to PHP object-oriented programming", "PHP string (String) Usage Summary", "Php+mysql Database Operations Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design based on Smarty template.