Get Smarty

Donate

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 glasses from Cheapglasses123.com and save up to 80%.

Where to buy prescription glasses? EyewearCanada.com is your best choice!

Visit www.sport-kick.com for cheap soccer cleats, sneakers and Soccer Jerseys updates

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.

Advertisement