首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

DateTime::getLastErrors

(PHP 5 >= 5.3.0, PHP 7)

DateTime :: getLastErrors - date_get_last_errors - 返回警告和错误

描述

面向对象的风格

代码语言:javascript
复制
public static array DateTime::getLastErrors ( void )

程序风格

代码语言:javascript
复制
array date_get_last_errors ( void )

返回解析日期/时间字符串时发现的警告和错误数组。

参数

该函数没有参数。

返回值

返回包含有关警告和错误信息的数组。

例子

示例 #1 DateTime::getLastErrors() example

面向对象的风格

代码语言:javascript
复制
<?php
try {
    $date = new DateTime('asdfasdf');
} catch (Exception $e) {
    // For demonstration purposes only...
    print_r(DateTime::getLastErrors());

    // The real object oriented way to do this is
    // echo $e->getMessage();
}
?>

程序风格

代码语言:javascript
复制
<?php
$date = date_create('asdfasdf');
print_r(date_get_last_errors());
?>

上面的例子会输出:

代码语言:javascript
复制
Array
(
   [warning_count] => 1
   [warnings] => Array
       (
           [6] => Double timezone specification
       )

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

)

示例输出中的索引6和0引用发生错误的字符串中的字符索引。

扫码关注腾讯云开发者

领取腾讯云代金券