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 всегда передаются как временные метки (англ. timestamp), что позволяет проектировщикам шаблонов использовать date_format для полного контроля над форматированием даты и также делает легким сравнение дат там, где это необходимо.

Note

Начиная с версии Smarty 1.4.0, вы можете передавать даты в Smarty в виде меток времени Unix (unix timestamps), mysql, или в любом другом виде, который понимает функция strtotime().

Example 18.4. Использование date_format


{$startDate|date_format}

   

Результат работы:


Jan 4, 2009

   

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

   

Результат работы:


2009/01/04

   

Даты можно ставнивать в шаблонах путем сравнения меток времени следующим образом:


{if $date1 < $date2}
    ... делаем что-то полезное ...
{/if}

   

Когда {html_select_date} используется в шаблоне, программист наверняка захочет преобразовать данные из формы назад в формат временной метки. Вот функция, которая поможет вам сделать это.

Example 18.5. Преобразование элементов формы ввода даты назад к временной метке


<?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 12 plus 12? (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