php Smarty date_format [格式化時(shí)間日期]
index.php:
$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:
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[日期轉(zhuǎn)換說(shuō)明]
%a - abbreviated weekday name according to the current locale
(根據(jù)當(dāng)?shù)馗袷捷敵觥靶瞧凇笨s寫格式)
%A - full weekday name according to the current locale
(根據(jù)當(dāng)?shù)馗袷捷敵觥靶瞧凇比Q格式)
%b - abbreviated month name according to the current locale
(根據(jù)當(dāng)?shù)馗袷捷敵觥霸隆笨s寫格式)
%B - full month name according to the current locale
(根據(jù)當(dāng)?shù)馗袷捷敵觥霸隆比Q格式)
%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 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 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 by
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 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本質(zhì)上是php的strftime()函數(shù)的一個(gè)包裝。
當(dāng)php被編譯的時(shí)候你可以或多或少的依靠系統(tǒng)的strftime()轉(zhuǎn)換有效的區(qū)分符。
可以查看系統(tǒng)手冊(cè)的有效區(qū)分符的全表.
- php格式化時(shí)間戳顯示友好的時(shí)間實(shí)現(xiàn)思路及代碼
- php自定義的格式化時(shí)間示例代碼
- php格式化時(shí)間戳
- PHP獲取當(dāng)前日期和時(shí)間及格式化方法參數(shù)
- PHP+Mysql日期時(shí)間如何轉(zhuǎn)換(UNIX時(shí)間戳和格式化日期)
- php格式化日期和時(shí)間格式化示例分享
- PHP格式化顯示時(shí)間date()函數(shù)代碼
- php時(shí)間戳格式化顯示友好的時(shí)間函數(shù)分享
- PHP日期函數(shù)date格式化UNIX時(shí)間的方法
- PHP使用gmdate實(shí)現(xiàn)將一個(gè)UNIX 時(shí)間格式化成GMT文本的方法
- PHP常用函數(shù)之格式化時(shí)間操作示例
相關(guān)文章
php定時(shí)計(jì)劃任務(wù)與fsockopen持續(xù)進(jìn)程實(shí)例
本文介紹了php中定時(shí)計(jì)劃任務(wù)的實(shí)現(xiàn)代碼,以及php持續(xù)進(jìn)程fsockopen的用法,需要的朋友可以參考下2014-05-05PHP實(shí)現(xiàn)的下載遠(yuǎn)程文件類定義與用法示例
這篇文章主要介紹了PHP實(shí)現(xiàn)的下載遠(yuǎn)程文件類定義與用法,結(jié)合具體實(shí)例形式分析了php封裝的下載遠(yuǎn)程文件操作類定義及使用方法,需要的朋友可以參考下2017-07-07PHP 實(shí)現(xiàn)base64編碼文件上傳出現(xiàn)問題詳解
這篇文章主要介紹了PHP 實(shí)現(xiàn)base64編碼文件上傳出現(xiàn)問題詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-09-09PHP的SQL注入實(shí)現(xiàn)(測(cè)試代碼安全不錯(cuò))
看黑客是如何入侵的,我們寫編寫php代碼的過程中,最好自己先測(cè)試效果。2011-02-02談PHP生成靜態(tài)頁(yè)面分析 模板+緩存+寫文件
談PHP生成靜態(tài)頁(yè)面 模板+緩存+寫文件,大家可以參考下代碼。2009-08-08PHP中使用協(xié)同程序?qū)崿F(xiàn)合作多任務(wù)
這篇文章指導(dǎo)你通過使用協(xié)同程序來(lái)實(shí)施任務(wù)調(diào)度,通過實(shí)例實(shí)現(xiàn)對(duì)技術(shù)的理解。我將在前三節(jié)做一個(gè)簡(jiǎn)單的背景介紹。如果你已經(jīng)有了比較好的基礎(chǔ),可以直接跳到“協(xié)同多任務(wù)處理”一節(jié)2013-07-07PHP實(shí)現(xiàn)讀取Excel文件的記錄(二)
在前文中介紹的方法有些麻煩,因?yàn)楸仨氁虞d很多的文件。本文介紹的方法簡(jiǎn)單了很多,只需要加載兩個(gè)文件即可。需要的可以參考一下2022-03-03詳解php中implode explode serialize json msgpack性能對(duì)比
這篇文章主要介紹了php中implode/explode、serialize、json、 msgpack性能對(duì)比,對(duì)性能感興趣的同學(xué),可以參考下2021-04-04php cookie名使用點(diǎn)號(hào)(句號(hào))會(huì)被轉(zhuǎn)換
php cookie名不能使用點(diǎn)號(hào)(句號(hào)),應(yīng)該說(shuō)可以使用點(diǎn)號(hào)的cookie名,但會(huì)被轉(zhuǎn)換,要知道為什么,祥看本文2014-10-10