Files
smarty/docs/en/designers/language-modifiers/language-modifier-date-format.xml
2005-05-27 16:25:02 +00:00

257 lines
7.6 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
<sect1 id="language.modifier.date.format">
<title>date_format</title>
<informaltable frame="all">
<tgroup cols="5">
<colspec colname="param" align="center" />
<colspec colname="type" align="center" />
<colspec colname="required" align="center" />
<colspec colname="default" align="center" />
<colspec colname="desc" />
<thead>
<row>
<entry>Parameter Position</entry>
<entry>Type</entry>
<entry>Required</entry>
<entry>Default</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>1</entry>
<entry>string</entry>
<entry>No</entry>
<entry>%b %e, %Y</entry>
<entry>This is the format for the outputted date.</entry>
</row>
<row>
<entry>2</entry>
<entry>string</entry>
<entry>No</entry>
<entry>n/a</entry>
<entry>This is the default date if the input is empty.</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<para>
This formats a date and time into the given
<ulink url="&url.php-manual;strftime">strftime()</ulink> format.
Dates can be passed to Smarty as unix
<ulink url="&url.php-manual;function.time">timestamps</ulink>, mysql timestamps
or any string made up of month day year, parsable by
<ulink url="&url.php-manual;strtotime">strtotime()</ulink>.
Designers can then use date_format to have complete control of the
formatting of the date. If the date passed to date_format is empty
and a second parameter is passed, that will be used as the date to
format.
</para>
<example>
<title>date_format</title>
<programlisting role="php">
<![CDATA[
<?php
$smarty->assign('yesterday', strtotime('-1 day'));
?>
]]>
</programlisting>
<para>
Where template is:
</para>
<programlisting>
<![CDATA[
{$smarty.now|date_format}
{$smarty.now|date_format:"%D"}
{$smarty.now|date_format:"%I:%M %p"}
{$yesterday|date_format}
{$yesterday|date_format:"%A, %B %e, %Y"}
{$yesterday|date_format:"%H:%M:%S"}
]]>
</programlisting>
<para>
This will output:
</para>
<screen>
<![CDATA[
Feb 6, 2001
02/06/01
02:33 pm
Feb 5, 2001
Monday, February 5, 2001
14:33:00
]]>
</screen>
</example>
<para>
<command>date_format</command> conversion specifiers:
<itemizedlist>
<listitem><para>
%a - abbreviated weekday name according to the current locale
</para></listitem>
<listitem><para>
%A - full weekday name according to the current locale
</para></listitem>
<listitem><para>
%b - abbreviated month name according to the current locale
</para></listitem>
<listitem><para>
%B - full month name according to the current locale
</para></listitem>
<listitem><para>
%c - preferred date and time representation for the current locale
</para></listitem>
<listitem><para>
%C - century number (the year divided by 100 and truncated to an integer, range 00 to 99)
</para></listitem>
<listitem><para>
%d - day of the month as a decimal number (range 00 to 31)
</para></listitem>
<listitem><para>
%D - same as %m/%d/%y
</para></listitem>
<listitem><para>
%e - day of the month as a decimal number, a single digit is preceded by a space (range 1
to 31)
</para></listitem>
<listitem><para>
%g - Week-based year within century [00,99]
</para></listitem>
<listitem><para>
%G - Week-based year, including the century [0000,9999]
</para></listitem>
<listitem><para>
%h - same as %b
</para></listitem>
<listitem><para>
%H - hour as a decimal number using a 24-hour clock (range 00 to 23)
</para></listitem>
<listitem><para>
%I - hour as a decimal number using a 12-hour clock (range 01 to 12)
</para></listitem>
<listitem><para>
%j - day of the year as a decimal number (range 001 to 366)
</para></listitem>
<listitem><para>
%k - Hour (24-hour clock) single digits are preceded by a blank. (range 0 to 23)
</para></listitem>
<listitem><para>
%l - hour as a decimal number using a 12-hour clock, single digits preceeded by a space
(range 1 to 12)
</para></listitem>
<listitem><para>
%m - month as a decimal number (range 01 to 12)
</para></listitem>
<listitem><para>
%M - minute as a decimal number
</para></listitem>
<listitem><para>
%n - newline character
</para></listitem>
<listitem><para>
%p - either `am' or `pm' according to the given time value, or the corresponding strings
for the
current locale
</para></listitem>
<listitem><para>
%r - time in a.m. and p.m. notation
</para></listitem>
<listitem><para>
%R - time in 24 hour notation
</para></listitem>
<listitem><para>
%S - second as a decimal number
</para></listitem>
<listitem><para>
%t - tab character
</para></listitem>
<listitem><para>
%T - current time, equal to %H:%M:%S
</para></listitem>
<listitem><para>
%u - weekday as a decimal number [1,7], with 1 representing Monday
</para></listitem>
<listitem><para>
%U - week number of the current year as a decimal number, starting with the first Sunday
as the first
day of the first week
</para></listitem>
<listitem><para>
%V - The ISO 8601:1988 week number of the current year as a decimal number, range 01 to
53, where week
1 is the first week that has at least 4 days in the current
year, and with Monday as the first day of the week.
</para></listitem>
<listitem><para>
%w - day of the week as a decimal, Sunday being 0
</para></listitem>
<listitem><para>
%W - week number of the current year as a decimal number, starting with the first Monday
as the first
day of the first week
</para></listitem>
<listitem><para>
%x - preferred date representation for the current locale without the time
</para></listitem>
<listitem><para>
%X - preferred time representation for the current locale without the date
</para></listitem>
<listitem><para>
%y - year as a decimal number without a century (range 00 to 99)
</para></listitem>
<listitem><para>
%Y - year as a decimal number including the century
</para></listitem>
<listitem><para>
%Z - time zone or name or abbreviation
</para></listitem>
<listitem><para>
%% - a literal `%' character
</para></listitem>
</itemizedlist>
<note>
<title>Programmers note</title>
<para>
date_format is essentially a wrapper to PHP's
<ulink url="&url.php-manual;strftime">strftime()</ulink> function.
You may have more or less conversion specifiers available depending
on your system's strftime() function where PHP was compiled. Check your
system's manpage for a full list of valid specifiers.
</para>
</note>
</para>
<para>
See also <link linkend="language.variables.smarty.now">$smarty.now</link>,
<ulink url="&url.php-manual;strftime">php function strftime()</ulink>,
<link linkend="language.function.html.select.date">{html_select_date}</link>
and <link linkend="tips.dates">date tips</link>.
</para>
</sect1>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->