Get Smarty

Donate

Donate Bitcoin Bitcoin
Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Buy cheap eyeglasses from Cheapglasses123.com and save up to 80%.

Buy prescription glasses from www.australiaglasses.com and save.

Cheap Glasses Now On Sale at GlassesPeople.com. Starts At $7.95.

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Brautkleider auf Topwedding.de

Find free files to download on allwhatyouwant.net

Looking For Affordable Wedding Dresses 2015 at Best Prices On TDBridal.com

Shop high quality cheap prom dresses on Dresswe.co.uk

Buy New Arrival Cheap Prom Dresses 2015 at JDBRIDAL Prom Dress Store

Advertisement

日期时间

一般经验而言,都是将时间戳作为日期时间值传递给Smarty。 模板设计者可以使用date_format 修饰器来控制日期时间的显示格式,还可以在需要时进行日期的比较。

Example 21.4. 使用 date_format


{$startDate|date_format}

    

输出:


Jan 4, 2009

    

{$startDate|date_format:"%Y/%m/%d"}

    

输出:


2009/01/04

    

日期的时间戳可以在模板内进行比较:


{if $order_date < $invoice_date}
   ...do something..
{/if}

    

当在模板内使用 {html_select_date}, 程序设计者会希望将输出的日期转换回时间戳。下面的函数可以做到这点:

Example 21.5. 转换元件的日期为时间戳


<?php

// this assumes your form elements are named
// startDate_Day, startDate_Month, startDate_Year

$startDate = makeTimeStamp($startDate_Year, $startDate_Month, $startDate_Day);

function makeTimeStamp($year='', $month='', $day='')
{
   if(empty($year)) {
       $year = strftime('%Y');
   }
   if(empty($month)) {
       $month = strftime('%m');
   }
   if(empty($day)) {
       $day = strftime('%d');
   }

   return mktime(0, 0, 0, $month, $day, $year);
}
?>

    

参见 {html_select_date}, {html_select_time}, date_format $smarty.now,

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 0 plus 0? (Are you human?)

Advertisement