Example 5-8. date_format[Date format]
index.php:
Copy CodeThe code is 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 CodeThe code is 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 CodeThe code is as follows:
%a-abbreviated weekday name According to the current locale
(output "Week" abbreviation 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 format according to local format)
%b-full month name According to the current locale
(output "month" full format according to local format)
%c-preferred Date and time representation for the current locale
%c-century Number (the year divided by and truncated to an integer, Range xx to 99)
%d-day of the month as a decimal number (range xx to 31)
%d-same as%m/%d/%y
%e-day of the month as a decimal number, a single digit was preceded by a
Space (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 xx to 23)
%i-hour as a decimal number using a 12-hour clock (range 12)
%j-day of the year as a decimal number (range 001 to 366)
%k-hour (24-hour clock) single digits is 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 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
%u-week number of the current year as a decimal number, starting with the first Sunday as the first day of the first wee K
%v-the ISO 8601:1988 Week number of the current year as a decimal number, range, where Week 1
Is the first week that have at least 4 days in the current year, and with Monday as the first day of the week.
%w-day of the week as a decimal, Sunday being 0
%w-week number of the current year as a decimal number, starting with the first Monday as the first day of the first wee 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 xx to 99)
%y-year as a decimal number including the century
%z-time zone or name or abbreviation
Percent-a literal '% ' character
Programmers Note:date_format is essentially a wrapper to PHP ' s strftime ()
function. Conversion specifiers available DEPENDING&NBSP
on your system ' s strftime () function where PH P was compiled. Check your
System's manpage for a full list of valid specifiers.
Programmer tip: Date_format is essentially PHP strftime () A wrapper for the function.
When PHP is compiled, you can rely more or less on the strftime () of the system to convert valid delimiters.
You can view the full table of valid delimiters for the system manual.