Format the time and date obtained from the function strftime().
Unix or mysql timestamp (parsable by
strtotime) can be passed to smarty.
Designers have full control over date format using date_format.
If the data passed to date_format is empty, the second parameter will be used as the time format.
test.php:
$config['date'] = '%I:%M %p';
$config['time'] = '%H:%M:%S';
$smarty->assign('config', $config);
$smarty->assign('yesterday', strtotime('-1 day '));
##test.html:{$smarty.now| date_format}<br>
{$smarty.now|date_format:"%D"}<br>
{$smarty.now|date_format:$config.date}<br>
{ $yesterday|date_format}<br>
{$yesterday|date_format:"%A, %B %e, %Y"}<br>
{$yesterday|date_format:$config.time}< ;br>
You need to pay attention to modifying the php.ini configuration:
Add date.timezone = Asia/Shanghai
Otherwise, an error will be reported:
It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function.
%a - the abbreviation of the day of the week in the current region
%A - the full name of the day of the week in the current region %b - the abbreviation of the month in the current region %B - the month in the current region The full name of %c - The preferred date and time expression for the current region %C - The century value (year divided by 100 and rounded, ranging from 00 to 99) %d - Day of the month, decimal number (range 01 to 31) %D - Same as %m/%d/%y %e - Day of the month Day, decimal number, with a space before the digit (ranging from '1' to '31')%g - Same as %G, but without the century%G - 4-digit year%h - Same as %b%H - Decimal hour in 24-hour format (range 00 to 23)%I - The decimal hour number in the 12-hour clock (range 00 to 12) %j - The day of the year, decimal number (range 001 to 366)%k - Hour, 24-hour format, no leading zeros
%l - Hour, 12-hour format, no leading zeros
%m - Decimal month (range 01 to 12 )
%M - decimal minutes
%n - newline character
%p - `am' or `pm' based on the given time value, or the current Corresponding string in locale
%r - Time in a.m. and p.m. notation
%R - Time in 24-hour notation
%S - Decimal seconds
%t - tab character
%T - current time, same as %H:%M:%S
%u - decimal representation of the day of the week [1 ,7], 1 means Monday
%U - The first week of the year, starting from the first Sunday of the first week as the first day
%V - The first day of the year Week in ISO 8601:1988 format, ranging from 01 to 53, with week 1 being the first week of the year with at least 4 days remaining, with Monday as the first day of the week. (Use %G or %g as the year component of the corresponding week number of the specified timestamp.)
%w - The day of the week, Sunday is 0
%W - The day of the year Week number, starting with the first Monday of the first week as the first day
%x - The preferred time representation for the current zone, excluding time
%X - The current The preferred time representation for the region, excluding dates
%y - Decimal year without century (range 00 to 99)
%Y - Decimal year including century
%Z - Time zone name or abbreviation