Get Smarty

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:

Check reviews of PHP Web Hosting, compatible with Smarty Templates

日付

経験上、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.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 0 plus 14? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
email marketing @ActiveCampaign
broadband deals @BroadbandGenie
Best UK Web Hosting @webhost.uk.net
Reliable UK and US Web Hosting @rshosting.com
Cheap US and UK Web Hosting @infrenion.com
I.T Certification Exams @pass-guaranteed.com
Certification Practice Tests @firsttrycertify.com
Certification Practice Exam Questions @ace-it-certifications.com
Broadband Speed Test @broadbandspeed.co.uk
bulk email software @americaint.com
ASP.NET hosting @aspnethosting.co.uk