PHP5 網管實驗室 2007 | 加入會員
PHP5網管實驗室
 
 線上討論區 繁/簡體
 
  下載 下載 我的訊息 部落格 線上討論區 文件搜尋 線上討論區 線上討論 我的訊息 我的訊息 會員服務 會員服務 回首頁 回首頁 
  [Download] [ Blog ] [ Search ] [ Forum ] [ PM ] [ Member ] [ HOME ]

  文章主目錄 :: PHP函式手冊 :: Date日期與時間函式庫   ||張貼文章||
 
strftime -- 根據本地端時間格式設定本地 端時間

相關連結 範例或相關連結 || 作者: || 時間:2003-06-06 01:52:39 ||最後更新:2003-06-06 02:12:49|| 列印 || 修改
strftime

(PHP 3, PHP 4 )
strftime -- 根據本地端時間格式設定本地 端時間
說明: string strftime ( string format [, int timestamp])

回傳一個已根據格式化的格式字串 使用目前的timestamp為現在時間的基準,
如果沒有timestamp. 月和週名及其他語系等等可以使用
setlocale()來設定.

下列為格式指定的範例:

*%a - abbreviated weekday name according to the current locale
*%A - full weekday name according to the current locale
*%b - abbreviated month name according to the current locale
*%B - full month name according to the current locale
*%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 01 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 - like %G, but without the century.
*%G - The 4-digit year corresponding to the ISO week number (see %V). This has the same format and value as %Y, except that if the ISO week number belongs to the previous or next year, that year is used instead.
*%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)
*%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

Warning

Sun Solaris seems to start with Sunday as 1 although ISO 9889:1999 (the current C standard) clearly specifies that it should be 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. (Use %G or %g for the year component that corresponds to the week number for the specified timestamp.)
*

%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 - day of the week as a decimal, Sunday being 0
*

%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

Note: Not all conversion specifiers may be supported by your C library, in which case they will not be supported by PHP's strftime(). This means that e.g. %e, %T, %R and %D (there might be more) will not work on Windows.

Example 1. strftime() locale examples

<?php
setlocale (LC_TIME, "C");
print (strftime ("%A in Finnish is "));
setlocale (LC_TIME, "fi_FI");
print (strftime ("%A, in French "));
setlocale (LC_TIME, "fr_FR");
print (strftime ("%A and in German "));
setlocale (LC_TIME, "de_DE");
print (strftime ("%A.\n"));
?>

This example works if you have the respective locales installed in your system.

Note: %G and %V, which are based on ISO 8601:1988 week numbers can give unexpected (albiet correct) results if the numbering system is not thoroughly understood. See %V above and example below.

Example 2. ISO 8601:1988 week number example

<?php
/* December 2002 / January 2003
ISOWk M Tu W Thu F Sa Su
----- ----------------------------
51 16 17 18 19 20 21 22
52 23 24 25 26 27 28 29
1 30 31 1 2 3 4 5
2 6 7 8 9 10 11 12
3 13 14 15 16 17 18 19 */

// Outputs: 12/28/2002 - %V,%G,%Y = 52,2002,2002
print "12/28/2002 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("12/28/2002")) . "\n";

// Outputs: 12/30/2002 - %V,%G,%Y = 1,2003,2002
print "12/30/2002 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("12/30/2002")) . "\n";

// Outputs: 1/3/2003 - %V,%G,%Y = 1,2003,2003
print "1/3/2003 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/3/2003")) . "\n";

// Outputs: 1/10/2003 - %V,%G,%Y = 2,2003,2003
print "1/10/2003 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/10/2003")) . "\n";



/* December 2004 / January 2005
ISOWk M Tu W Thu F Sa Su
----- ----------------------------
51 13 14 15 16 17 18 19
52 20 21 22 23 24 25 26
53 27 28 29 30 31 1 2
1 3 4 5 6 7 8 9
2 10 11 12 13 14 15 16 */

// Outputs: 12/23/2004 - %V,%G,%Y = 52,2004,2004
print "12/23/2004 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("12/23/2004")) . "\n";

// Outputs: 12/31/2004 - %V,%G,%Y = 53,2004,2004
print "12/31/2004 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("12/31/2004")) . "\n";

// Outputs: 1/2/2005 - %V,%G,%Y = 53,2004,2005
print "1/2/2005 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/2/2005")) . "\n";

// Outputs: 1/3/2005 - %V,%G,%Y = 1,2005,2005
print "1/3/2005 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/3/2005")) . "\n";

?>

See also setlocale() and mktime() and the Open Group specification of strftime().


strftime

相關連結 範例或相關連結 || 作者:my.bluesky || 時間:2003-07-27 22:40 || 最後更新:2003-07-27 22:40|| 修改|| 刪除
strftime
(PHP 3, PHP 4 )

strftime -- 根據區域設置格式化本地時間�日期
說明
string strftime ( string format [, int timestamp])


傳回用給定的格式字串對給出的 timestamp 進行格式輸出後的字串。如果沒有給出時間戳則用當前的本地時間。月份和星期幾以及其它和語言有關的字串寫法和用 setlocale() 設定的當前的區域有關。

格式字串能識別下列轉換標記:


%a - 當前區域星期幾的簡寫

%A - 當前區域星期幾的全稱

%b - 當前區域月份的簡寫

%B - 當前區域月份的全稱

%c - 當前區域首選的日期時間表達

%C - 世紀值(年份除以 100 後取整,範圍從 00 到 99)

%d - 月份中的第幾天,十進制數字(範圍從 01 到 31)

%D - 和 %m/%d/%y 一樣

%e - 月份中的第幾天,十進制數字,一位的數字前會加上一個空格(範圍從 ' 1' 到 '31')

%g - 和 %G 一樣,但是沒有世紀

%G - 4 位數的年份,符合 ISO 星期數(參見 %V)。和 %V 的格式和值一樣,只除了如果 ISO 星期數屬於前一年或者後一年,則使用那一年。

%h - 和 %b 一樣

%H - 24 小時制的十進制小時數(範圍從 00 到 23)

%I - 12 小時制的十進制小時數(範圍從 00 到 12)

%j - 年份中的第幾天,十進制數(範圍從 001 到 366)

%m - 十進制月份(範圍從 01 到 12)

%M - 十進制分鐘數

%n - 換行符

%p - 根據給定的時間值為 `am' 或 `pm',或者當前區域設置中的相應字串

%r - 用 a.m. 和 p.m. 符號的時間

%R - 24 小時符號的時間

%S - 十進制秒數

%t - 制表符

%T - 當前時間,和 %H:%M:%S 一樣

%u - 星期幾的十進制數表達 [1,7],1 表示星期一


警告
儘管 ISO 9889:1999(當前的 C 標準)明確指出一周從星期一開始,但是 Sun Solaris 的一周似乎從星期天開始並作為 1。


%U - 本年的第幾周,從第一周的第一個星期天作為第一天開始

%V - 本年第幾周的 ISO 8601:1988 格式,範圍從 01 到 53,第 1 周是本年第一個至少還有 4 天的星期,星期一作為每周的第一天。(用 %G 或者 %g 作為指定時間戳相應周數的年份組成。)

%W - 本年的第幾周數,從第一周的第一個星期一作為第一天開始

%w - 星期中的第幾天,星期天為 0

%x - 當前區域首選的時間表示法,不包括時間

%X - 當前區域首選的時間表示法,不包括日期

%y - 沒有世紀數的十進制年份(範圍從 00 到 99)

%Y - 包括世紀數的十進制年份

%Z - 時區名或縮寫

%% - 文字上的 `%' 字元

註: 可能不是所有的轉換標記都被 C 庫文件支援,這種情況下 PHP 的 strftime() 也不支援。這意味著例如 %e, %T 和 %D(可能更多)在 Windows 下不起作用。

例子 1. strftime() 例子

setlocale (LC_TIME, "C");
print (strftime ("%A in Finnish is "));
setlocale (LC_TIME, "fi_FI");
print (strftime ("%A, in French "));
setlocale (LC_TIME, "fr_FR");
print (strftime ("%A and in German "));
setlocale (LC_TIME, "de_DE");
print (strftime ("%A.\n"));


本例在你的系統中安裝有各自的區域設置後才能工作。

參見 setlocale() 和 mktime() 以及 Open Group specification of strftime()。

文章來源:http://linux.tnc.edu.tw/techdoc/php/php_big5/function.strftime.html

 

網站地圖 廣告刊登 合作提案 關於作者 連絡我們 設為首頁  
   
     程式管理: jacch (jack chen)PHP5網管實驗室版權所有
     2001 - 2007 copyright by jacch . All rights reserved.. counter