| Parameter Position | Type | Required | Default | Description |
|---|---|---|---|---|
| 1 | string | No | %b %e, %Y | This is the format for the outputted date. |
| 2 | string | No | n/a | This is the default date if the input is empty. |
This formats a date and time into the given strftime() format. Dates can be passed to Smarty as unix timestamps, mysql timestamps or any string made up of month day year (parsable by strtotime). Designers can then use date_format to have complete control of the formatting of the date. If the date passed to date_format is empty and a second parameter is passed, that will be used as the date to format.
此函式使用 strftime() 函式將日期與時間格式化。在傳到 Smarty 前,時間格式可 以是 unix 或 mysql 的時間戳記格式,或者是自定的格式(使用 strtotime 函式分析)。設計 者可以使用 date_format 函式控制日期與時間的格式,如果傳給 date_format 函式時日期是空 白的而只有秒的參數的話,秒的參數會被視為日期的參數而被格式化。
date_format conversion specifiers:
date_format 轉換參數:
%a - abbreviated weekday name according to the current locale
%a - 根據所在時區使用週的縮寫
%A - full weekday name according to the current locale
%A - 根據所在時區使用週的全名
%b - abbreviated month name according to the current locale
%b - 根據所在時區使用月的縮寫
%B - full month name according to the current locale
%B - 根據所在時區使用月的全名
%c - preferred date and time representation for the current locale
%c - 根據所在時區使用所設定的日期與時間
%C - century number (the year divided by 100 and truncated to an integer, range 00 to 99)
%C - 世紀的數字值(西元數除以100且截成整數,範圍為00到99)
%d - day of the month as a decimal number (range 00 to 31)
%d - 十進位的日期(範圍為00到31)
%D - same as %m/%d/%y
%D - 同 %m/%d/%y
%e - day of the month as a decimal number, a single digit is preceded by a space (range 1 to 31)
%e - 十進位的日期,如果只有一個數字的話則前面補一個空白(範圍為0到31)
%g - Week-based year within century [00,99]
%g - 以週為基準月 [00,99]
%G - Week-based year, including the century [0000,9999]
%G - 以週為基準月包含世紀 [0000,9999]
%h - same as %b
%h - 同 %b
%H - hour as a decimal number using a 24-hour clock (range 00 to 23)
%H - 24小時制的十進位數字時(範圍為00到23)
%I - hour as a decimal number using a 12-hour clock (range 01 to 12)
%I - 12小時制的十進位數字時(範圍為00到12)
%j - day of the year as a decimal number (range 001 to 366)
%j - 十進位年內的日子數(範圍為001到366)
%k - Hour (24-hour clock) single digits are preceded by a blank. (range 0 to 23)
%k - 24小時制的時,如果只有一個數字的話前面補一個空白(範圍從0到23)
%l - hour as a decimal number using a 12-hour clock, single digits preceeded by a space (range 1 to 12)
%l - 12小時制的十進位數字時,如果只有一個數字的話前面補一個空白(範圍從0到12)
%m - month as a decimal number (range 01 to 12)
%m - 十進位的月(範圍從01到12)
%M - minute as a decimal number
%M - 十進位的分
%n - newline character
%n - 換行符號
%p - either `am' or `pm' according to the given time value, or the corresponding strings for the current locale
%p - 根據時區給的時間值補上 `am' 或 `pm'
%r - time in a.m. and p.m. notation
%r - 時間以 a.m. 與 p.m. 方式呈現
%R - time in 24 hour notation
%R - 時間以 24 小時方式呈現
%S - second as a decimal number
%S - 十進位的秒
%t - tab character
%t - tab 字元
%T - current time, equal to %H:%M:%S
%T - 現在時間,同 %H:%M:%S
%u - weekday as a decimal number [1,7], with 1 representing Monday
%u - 十進位的星期數 [1,7],其中1代表星期一
%U - week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week
%U - 十進位今年的週數,以第一個星期日當作第一個禮拜的第一天
%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.
%V - ISO 8601:1988 格式今年週數的十進位數字,範圍由01到53,其中1代表著有最少四天在今年的第一週且星期一是週的第一天
%w - day of the week as a decimal, Sunday being 0
%w - 十進位的週數字,星期日是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
%W - 十進位的今年現在週數,以禮拜一當作第一個禮拜的第一天
%x - preferred date representation for the current locale without the time
%x - 現在時區有日期沒有時間的格式
%X - preferred time representation for the current locale without the date
%X - 現在時區有時間沒有日期的格式
%y - year as a decimal number without a century (range 00 to 99)
%y - 沒有世紀的十進位年數(範圍從00到99)
%Y - year as a decimal number including the century
%Y - 包含世紀的十進位年數
%Z - time zone or name or abbreviation
%Z - 時間區域或名稱或簡寫
%% - a literal `%' character
%% - 一個 `%' 字元
Programmers note: date_format is essentially 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.
程式人員提醒: date_format 基本上是 PHP strftime() 函式的包裝函式,每個人會因為自己的系統在編 譯 PHP 時狀況的不同而有不同的參數,因此請聯絡你的系統的管理者以了解你可以使用的參數。