PHP date_parse()
函数与 date_parse_from_format() 的工作原理相同,它以指定的格式提供有关特定日期的完整信息,并以数组的形式返回数据。
语法
array date_parse ( string $date )
参数
参数 | 描述 | 必须/可选 |
---|---|---|
date | 指定日期 | 必须 |
返回
此函数在成功时返回包含有关解析日期的信息的数组,在失败时返回 FALSE。
例子1
<?php
print_r(date_parse("2018-07-10 12:30:45.5"));
?>
输出:
Array ( [year] => 2018 [month] => 7 [day] => 10 [hour] => 12 [minute] => 30 [second]
=> 45 [fraction] => 0.5 [warning_count] => 0 [warnings] => Array
=> 45 [fraction] => 0.5 [warning_count] => 0 [warnings] => Array
例子2
<?php
print_r(date_parse("2020-07-10 01:30:60.0"));
?>
输出:
Array ( [year] => 2020 [month] => 7 [day] => 10 [hour] => 1 [minute] => 30 [second]
=> 60 [fraction] => 0 [warning_count] => 1 [warnings] => Array ( [22] => The parsed time was invalid )
[error_count] => 0 [errors] => Array ( ) [is_localtime] => )
=> 60 [fraction] => 0 [warning_count] => 1 [warnings] => Array ( [22] => The parsed time was invalid )
[error_count] => 0 [errors] => Array ( ) [is_localtime] => )
例子3
<?php
print_r(date_parse("2018-7-12 12:00:00.5"));
?>
输出:
Array ( [year] => 2018 [month] => 7 [day] => 12 [hour] => 12 [minute] => 0 [second]
=> 0 [fraction] => 0.5 [warning_count] => 0 [warnings] => Array ( )
=> 0 [fraction] => 0.5 [warning_count] => 0 [warnings] => Array ( )