PHP如何使用date_get_last_errors()函数?代码实例

2021年3月25日13:10:04 发表评论 847 次浏览

date_get_last_errors()函数PHP中的内置函数, 用于返回警告和错误。此函数解析日期/时间字符串, 并返回警告和错误的数组。

语法如下:

  • 程序风格:
    array date_get_last_errors( void )
  • 面向对象的样式:
    array DateTime::getLastErrors( void )

参数:此函数不接受任何参数。

返回值:该函数返回一个数组, 其中包含有关警告和错误的信息。

下面的程序说明了PHP中的date_get_last_errors()函数:

程序1:

<?php
$date = date_create();
print_r(date_get_last_errors());
?>

输出如下:

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

    [error_count] => 0
    [errors] => Array
        (
        )

)

程式2:

<?php
try {
     $date = new DateTime( 'vgdgh' );
} 
catch (Exception $e ) {
      
     // For demonstration purposes only...
     print_r(DateTime::getLastErrors());
}
?>

输出如下:

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

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

)

相关文章:

  • PHP | gmstrftime()函数
  • PHP | gettimeofday()函数
  • PHP | strptime()函数

参考: http://php.net/manual/en/datetime.getlasterrors.php


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: