最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Smarty日期時間操作方法示例

 更新時間:2016年11月15日 11:15:25   作者:陳達輝  
這篇文章主要介紹了Smarty日期時間操作方法,結(jié)合實例形式較為詳細的分析了Smarty日期時間操作相關(guān)函數(shù)、參數(shù)功能及使用技巧,需要的朋友可以參考下

本文實例講述了Smarty日期時間操作方法。分享給大家供大家參考,具體如下:

$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顯示格式化當前日期

{$smarty.now|date_format}
{$smarty.now|date_format:"%A, %m %e, %Y"}
{$smarty.now|date_format:"%H:%M:%S"}

smarty符號說明

%Y表示年份

%m表示月份

%d表示日

%A 表示星期幾,

%H 表示小時

%M表示分鐘

%s表示秒

如果日期是變量,可以:

{$yesterday|date_format:"%A, %B %e, %Y"}
{$yesterday|date_format:"%H:%M:%S"}

smarty內(nèi)部日期函數(shù)html_select_date()使用說明

prefix string類型 默認前綴名為"Date_
start_year string類型 默認為當前年份 仍可以用(+/-N)模式表示 如start_year="-10" option就從1999年開始
end_year string類型 默認同上 可用(+/-N)模式表示 如end_year="+5" option就到2014為止
field_order string類型 默認MDY 即按月日年的順序 排放select
month_format string類型 默認%B 即顯示為January、February、etc. %b格式為簡寫形式 顯示月份的前三個字母 %m格式為數(shù)字顯示月份
day_format string類型 默認%02d 數(shù)字表示從01~31 并且與月份不關(guān)聯(lián) %b格式為二進制顯示格式 很少用

其他屬性:

display_days boolean類型 控制day的select是否顯示
display_months boolean類型 控制month的select是否顯示
display_years boolean類型 控制year的select是否顯示
year_as_text boolean類型 true顯示為text型年份 false顯示為下拉菜單型
reverse_years boolean 類型 true的情況下年份為倒序顯示
year_size string 類型 值在大于1的情況下均為下拉菜單型輸出 0或1時為上下箭頭控制
month_size 同上
day_size 同上

示例如下:

{html_select_date prefix="StartDate" time=$time start_year="-5" end_year="+1" display_days=false}

OUTPUT: (current year is 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="10">October</option>
<option value="11">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="2000" selected>2000</option>
<option value="2001">2001</option>
</select>

其他的屬性,請自行調(diào)試。這個日期處理函數(shù)的缺點是day與month不關(guān)聯(lián),不如用js處理

其中js顯示day的函數(shù)可以如下定義:

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;
 }
}
}

更多關(guān)于Smarty相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《smarty模板入門基礎(chǔ)教程》、《PHP模板技術(shù)總結(jié)》、《PHP基于pdo操作數(shù)據(jù)庫技巧總結(jié)》、《PHP運算與運算符用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家基于smarty模板的PHP程序設(shè)計有所幫助。

相關(guān)文章

  • 大家須知簡單的php性能優(yōu)化注意點

    大家須知簡單的php性能優(yōu)化注意點

    通過本文給大家介紹在什么情況下可能遇到性能問題,php性能問題的解決方向及優(yōu)化點,對php性能優(yōu)化注意點相關(guān)知識感興趣的朋友一起學習吧
    2016-01-01
  • 新浪微博API開發(fā)簡介之用戶授權(quán)(PHP基礎(chǔ)篇)

    新浪微博API開發(fā)簡介之用戶授權(quán)(PHP基礎(chǔ)篇)

    己在開發(fā)和學習的過程中,感覺雖然沒有太大難度,但還是有一些問題是需要我們注意的,今天就我在開發(fā)和學習的過程中,簡單的對利用PHP進行新浪微博API開發(fā)的內(nèi)容進行一個整理和說明
    2011-09-09
  • php框架CodeIgniter使用redis的方法分析

    php框架CodeIgniter使用redis的方法分析

    這篇文章主要介紹了php框架CodeIgniter使用redis的方法,結(jié)合實例形式分析了redis的安裝、設(shè)置及CodeIgniter使用redis的相關(guān)操作技巧與注意事項,需要的朋友可以參考下
    2018-04-04
  • 最新評論

    山东| 琼海市| 丹棱县| 河津市| 大冶市| 务川| 错那县| 台东市| 永善县| 寿光市| 屏山县| 石棉县| 石家庄市| 垫江县| 百色市| 枣强县| 金塔县| 大厂| 永年县| 原平市| 建阳市| 重庆市| 栾川县| 寻乌县| 巴青县| 墨竹工卡县| 宽甸| 苏尼特左旗| 乌兰县| 公主岭市| 峡江县| 万源市| 兴海县| 四会市| 闻喜县| 阿瓦提县| 镇原县| 灯塔市| 广东省| 中江县| 玉龙|