Example 5-8. date_format[Date format]
index.php:
Copy Code code as follows:
$smarty = new Smarty;
$smarty->assign (' Yesterday ', Strtotime ('-1 day '));
$smarty->display (' Index.tpl ');
INDEX.TPL:
{$smarty. Now|date_format}
{$smarty. Now|date_format: "%A,%B%e,%Y"}
{$smarty. Now|date_format: "%h:%m:%s"}
{$yesterday |date_format}
{$yesterday |date_format: "%A,%B%e,%Y"}
{$yesterday |date_format: "%h:%m:%s"}
OUTPUT:
Copy Code code as follows:
Feb 6, 2001
Tuesday, February 6, 2001
: 33:00
Feb 5, 2001
Monday, February 5, 2001
: 33:00
Example 5-9. Date_format conversion specifiers[Date Conversion description]
Copy Code code as follows:
%a-abbreviated weekday name According to the current locale
(Output "Week" abbreviated format according to local format)
%a-full weekday name According to the current locale
(output "Week" full format according to local format)
%b-abbreviated month name According to the current locale
(output "month" abbreviation according to local format)
%b-full month name According to the current locale
(output "Month" in full format according to local format)
%c-preferred Date and time representation for the current locale
%c-century Number (the year divided from and truncated to a integer, range to 99)
%d-day of the month as a decimal number (range to 31)
%d-same as%m/%d/%y
%e-day of the month as a decimal number, a single digit be preceded by a
Spaces (range 1 to 31)
%g-week-based year within century [00,99]
%g-week-based year, including the century [0000,9999]
%h-same as%b
%h-hour as a decimal number using a 24-hour clock (range to 23)
%i-hour as a decimal number using a 12-hour clock (range to 12)
%j-day of the year as a decimal number (range 001 to 366)
%k-hour (24-hour clock) single digits are preceded by a blank. (range 0 to 23)
%l-hour as a decimal number using a 12-hour clock, single digits preceeded by
A space (range 1 to 12)
%m-month as a decimal number (range to 12)
%m-minute as a decimal number
%n-newline character
%p-either ' am ' or ' PM ' according to the given time value, or the corresponding strings for the current locale
%r-time in a.m. and p.m. notation
%r-time in hour notation
%s-second as a decimal number
%t-tab character
%t-current time, equal to%h:%m:%s
%u-weekday as a decimal number [1,7], with 1 representing Monday
K
%v-the ISO 8601:1988 Week number of the current year as a decimal number, range to, where Week 1
Is the "Week" has at least 4, and with Monday as the the week.
%w-day of the week as a decimal, Sunday being 0
K
%x-preferred date representation for the current locale without the time
%x-preferred time representation for the current locale without the date
%y-year as a decimal number without a century (range to 99)
%y-year as a decimal number including the century
%z-time zone or name or abbreviation
%%-a literal '% ' character
Programmers Note:date_format is essentially a wrapper to PHP ' s strftime ()
function. You could have more or less conversion specifiers available depending
On your system ' s strftime () function where PHP is compiled. Check your
System ' s manpage for a full list of valid specifiers.
Programmer Tip: Date_format is essentially a wrapper for the PHP strftime () function.
When PHP is compiled, you can more or less rely on the system's Strftime () to convert a valid delimiter.
You can view a full table of valid qualifiers for the system manual.