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 instructions]
Copy codeThe Code is as follows:
% A-abbreviated weekday name according to the current locale
(The abbreviated format of "Week" is output according to the local format)
% A-full weekday name according to the current locale
(The full name format of "Week" is output according to the local format)
% B-abbreviated month name according to the current locale
(The abbreviated format of "month" is output according to the local format)
% B-full month name according to the current locale
(The full name format of "month" is output according to the local format)
% C-preferred date and time representation for the current locale
% C-century number (the year divided by 100 and truncated to an integer, range 00 to 99)
% D-day of the month as a decimal number (range 00 to 31)
% D-same as % m/% d/% y
% E-day of the month as a decimal number, a single digit is preceded by
Space (range 1 to 31)
% G-Week-based year within century []
% G-Week-based year, including the century [snapshot, 9999]
% H-same as % B
% H-hour as a decimal number using a 24-hour clock (range 00 to 23)
% I-hour as a decimal number using a 12-hour clock (range 01 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
A space (range 1 to 12)
% M-month as a decimal number (range 01 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 24 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 week
% 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.
% 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 week
% 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 00 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 essential a wrapper to PHP's strftime ()
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.
Programmer's note: date_format is essentially a packaging of php's strftime () function.
When php is compiled, you can more or less rely on the system's strftime () to convert effective delimiters.
You can view the full table of valid delimiters in the system manual.