date_parse()函數(shù)
date_parse()函數(shù)接受日期作為參數(shù),對(duì)其進(jìn)行解析,然后以數(shù)組形式返回有關(guān)給定日期的信息。
date_parse($date)
序號(hào) | 參數(shù)及說(shuō)明 |
---|---|
1 | date(必需) 這是您需要其相關(guān)信息的日期字符(應(yīng)被strtotime()接受)。 |
date_parse()函數(shù)返回一個(gè)數(shù)組,其中包含有關(guān)給定日期的信息。如果失敗,此函數(shù)將返回布爾值false。
此函數(shù)最初是在PHP版本5.2.0中引入的,并且可以在所有更高版本中使用。
以下示例演示了date_parse()函數(shù)的用法-
<?php print_r(date_parse("2009-11-09 07:30:25.5")); ?>測(cè)試看看?/?
輸出結(jié)果
Array ( [year] => 2009 [month] => 11 [day] => 9 [hour] => 7 [minute] => 30 [second] => 25 [fraction] => 0.5 [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => )
以下示例打印有關(guān)各種不同日期的信息-
<?php $date1 = date_parse("25-09-1989"); print_r($date1); print("\n"); $date2 = date_parse("14-02-2012"); print_r($date2); print("\n"); $date3 = date_parse("11-19-2005"); print_r($date3); print("\n"); $date4 = date_parse("17-07-2020"); print_r($date4); print("\n"); $date5 = date_parse("07-11-1995"); print_r($date5); print("\n"); ?>測(cè)試看看?/?
輸出結(jié)果
Array ( [year] => 1989 [month] => 9 [day] => 25 [hour] => [minute] => [second] => [fraction] => [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => ) Array ( [year] => 2012 [month] => 2 [day] => 14 [hour] => [minute] => [second] => [fraction] => [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => ) Array ( [year] => [month] => [day] => [hour] => [minute] => [second] => [fraction] => [warning_count] => 1 [warnings] => Array ( [5] => Double timezone specification ) [error_count] => 2 [errors] => Array ( [0] => Unexpected character [1] => Unexpected character ) [is_localtime] => 1 [zone_type] => 1 [zone] => -68400 [is_dst] => ) Array ( [year] => 2020 [month] => 7 [day] => 17 [hour] => [minute] => [second] => [fraction] => [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => ) Array ( [year] => 1995 [month] => 11 [day] => 7 [hour] => [minute] => [second] => [fraction] => [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => )
以下示例演示了相對(duì)格式的date_parse()-
<?php print_r(date_parse("2009-18-18")); print("\n"); print_r(date_parse("1990-06-06 +52 week +25 hour")); ?>測(cè)試看看?/?
這將產(chǎn)生以下輸出-
Array ( [year] => 2009 [month] => 1 [day] => 1 [hour] => [minute] => [second] => [fraction] => [warning_count] => 0 [warnings] => Array ( ) [error_count] => 1 [errors] => Array ( [6] => Unexpected character ) [is_localtime] => 1 [zone_type] => 1 [zone] => -64800 [is_dst] => ) Array ( [year] => 1990 [month] => 6 [day] => 6 [hour] => [minute] => [second] => [fraction] => [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => [relative] => Array ( [year] => 0 [month] => 0 [day] => 364 [hour] => 25 [minute] => 0 [second] => 0 ) )