您的位置:首页 > 编程语言 > PHP开发

Smarty - date_format [格式化时间日期]

2011-03-29 16:03 721 查看
 

Example 5-8. date_format[日期格式]

 

 1 index.php:
2
3  $smarty = new Smarty;
4  $smarty->assign('yesterday', strtotime('-1 day'));
5  $smarty->display('index.tpl');
6
7 index.tpl:
8
9
10 {$smarty.now|date_format}
11 {$smarty.now|date_format:"%A, %B %e, %Y"}
12 {$smarty.now|date_format:"%H:%M:%S"}
13 {$yesterday|date_format}
14 {$yesterday|date_format:"%A, %B %e, %Y"}
15 {$yesterday|date_format:"%H:%M:%S"}

Example 5-9. date_format conversion specifiers[日期转换说明]

 

 1 %a - abbreviated weekday name according to the current locale
2 (根据当地格式输出“星期”缩写格式)
3
4  %A - full weekday name according to the current locale
5 (根据当地格式输出“星期”全称格式)
6
7  %b - abbreviated month name according to the current locale
8 (根据当地格式输出“月”缩写格式)
9
10  %B - full month name according to the current locale
11 (根据当地格式输出“月”全称格式)
12
13  %c - preferred date and time representation for the current locale
14
15 %C - century number (the year divided by 100 and truncated to an integer, range 00 to 99)
16
17 %d - day of the month as a decimal number (range 00 to 31)
18
19 %D - same as %m/%d/%y
20
21 %e - day of the month as a decimal number, a single digit is preceded by a
22 space (range 1 to 31)
23
24 %g - Week-based year within century [00,99]
25
26 %G - Week-based year, including the century [0000,9999]
27
28 %h - same as %b
29
30 %H - hour as a decimal number using a 24-hour clock (range 00 to 23)
31
32 %I - hour as a decimal number using a 12-hour clock (range 01 to 12)
33
34 %j - day of the year as a decimal number (range 001 to 366)
35
36 %k - Hour (24-hour clock) single digits are preceded by a blank. (range 0 to 23)
37
38 %l - hour as a decimal number using a 12-hour clock, single digits preceeded by
39 a space (range 1 to 12)
40
41 %m - month as a decimal number (range 01 to 12)
42
43 %M - minute as a decimal number
44
45 %n - newline character
46
47 %p - either `am' or `pm' according to the given time value, or the corresponding strings for the current locale
48
49 %r - time in a.m. and p.m. notation
50
51 %R - time in 24 hour notation
52
53 %S - second as a decimal number
54
55 %t - tab character
56
57 %T - current time, equal to %H:%M:%S
58
59 %u - weekday as a decimal number [1,7], with 1 representing Monday
60
61 %U - week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week
62
63 %V - The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1
64 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week.
65
66 %w - day of the week as a decimal, Sunday being 0
67
68 %W - week number of the current year as a decimal number, starting with the first Monday as the first day of the first week
69
70 %x - preferred date representation for the current locale without the time
71
72 %X - preferred time representation for the current locale without the date
73
74 %y - year as a decimal number without a century (range 00 to 99)
75
76 %Y - year as a decimal number including the century
77
78 %Z - time zone or name or abbreviation
79
80 %% - a literal `%' character
81
82

程序员提示:date_format本质上是php的strftime()函数的一个包装。
当php被编译的时候你可以或多或少的依靠系统的strftime()转换有效的区分符。
可以查看系统手册的有效区分符的全表.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息