(PHP 5 >= 5.1.0)
strptime — 解析由 strftime() 生成的日期/時間
說明
array strptime ( string$date
, string $format
)
strptime() 返回一個將
date
解析后的數(shù)組,如果出錯返回 FALSE
。
月份和星期幾的名字以及其它與語種有關(guān)的字符串對應(yīng)于
setlocale()設(shè)定的當(dāng)前區(qū)域(LC_TIME
)。
參數(shù)
date
(string)
被解析的字符串(例如從 strftime() 返回的)
format
(string)
date
所使用的格式(例如同
strftime() 中所使用的相同)。
更多有關(guān)格式選項的信息見 strftime() 頁面。
返回值
返回一個數(shù)組 或者在失敗時返回 FALSE
數(shù)組中包含以下單元
鍵名
說明
tm_sec
當(dāng)前分鐘內(nèi)的秒數(shù)(0-61)
tm_min
當(dāng)前小時內(nèi)的分鐘數(shù)(0-59)
tm_hour
午夜起的小時數(shù)(0-23)
tm_mday
月份中的第幾天(1-31)
tm_mon
自一月起過了幾個月(0-11)
tm_year
自 1900 年起過了幾年
tm_wday
自星期天起過了幾天(0-6)
tm_yday
本年自一月一日起過了多少天(0-365)
unparsed
date
中未能通過指定的
format
識別的部分
范例
Example #1 strptime() 例子
<?php
$format = '%d/%m/%Y %H:%M:%S';
$strf = strftime($format);
echo "$strfn";
print_r(strptime($strf, $format));
?>
以上例程的輸出類似于:
03/10/2004 15:54:19 Array ( [tm_sec] => 19 [tm_min] => 54 [tm_hour] => 15 [tm_mday] => 3 [tm_mon] => 9 [tm_year] => 104 [tm_wday] => 0 [tm_yday] => 276 [unparsed] => )
注釋
Note: 此函數(shù)未在 Windows 平臺下實現(xiàn)。
Note:
Internally, this function calls the strptime() function provided by the system's C library. This function can exhibit noticeably different behaviour across different operating systems. The use of date_parse_from_format(), which does not suffer from these issues, is recommended on PHP 5.3.0 and later.
Note:
"tm_sec" includes any leap seconds (currently upto 2 a year). For more information on leap seconds, see the » Wikipedia article on leap seconds.
Note:
Prior to PHP 5.2.0, this function could return undefined behaviour. Notably, the "tm_sec", "tm_min" and "tm_hour" entries would return undefined values.
參見
checkdate() - 驗證一個格里高里日期 strftime() - 根據(jù)區(qū)域設(shè)置格式化本地時間/日期 date_parse_from_format() - Get info about given date formatted according to the specified format DateTime::createFromFormat() - Returns new DateTime object formatted according to the specified format