PHP 日期和时间函数

PHPdate_get_last_errors()函数表示如果在解析日期字符串时出现任何错误,此函数将在输出中显示警告/错误。

语法

date_get_last_errors(); 

例子1

<?php
date_create('12345~211');
print_r(date_get_last_errors());
?> 

输出:

Array
(
    [warning_count] => 0
    [warnings] => Array
        (
        )

    [error_count] => 5
    [errors] => Array
        (
            [4] => Unexpected character
            [5] => Unexpected character
            [6] => Unexpected character
            [7] => Unexpected character
            [8] => Unexpected character
        )

)

例子2

<?php
date_create("ghg");
print_r(date_get_last_errors());
?> 

输出:

Array
(
[warning_count] => 0
[warnings] => Array
(
)

[error_count] => 1
[errors] => Array
(
[0] => The timezone could not be found in the database
)

)