Get Smarty

Donate

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

Advertisement

日付

経験上、Smarty に渡す日付は常に タイムスタンプ型 にしておくことをお勧めします。これにより、テンプレートデザイナーは date_format 修飾子で日付の書式を自由にコントロールできるようになります。 また、必要なら日付の比較も簡単に行えます。

Example 18.4. date_format の使用


{$startDate|date_format}

    

出力はこのようになります。


Jan 4, 2009

    

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

    

出力はこのようになります。


2009/01/04

    

テンプレートで日付を比較するには、タイムスタンプを使用します。


{if $order_date < $invoice_date}
   ...何かを行います
{/if}

    

テンプレートで {html_select_date} を使用する場合、 おそらくプログラマはフォームからの出力をタイムスタンプ型に変換したいでしょう。 それを行うのに役立つ関数を次に示します。

Example 18.5. フォームの日付要素をUNIXタイムスタンプ型に変換する


<?php

// フォームの要素の名前が 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

Sponsors [info]

Sponsors