DateTime::getLastErrors
(PHP 5 >= 5.3.0, PHP 7)
DateTime :: getLastErrors - date_get_last_errors - 返回警告和错误
描述
面向对象的风格
public static array DateTime::getLastErrors ( void )
程序风格
array date_get_last_errors ( void )
返回解析日期/时间字符串时发现的警告和错误数组。
参数
该函数没有参数。
返回值
返回包含有关警告和错误信息的数组。
例子
示例 #1 DateTime::getLastErrors() example
面向对象的风格
<?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();
}
?>
程序风格
<?php
$date = date_create('asdfasdf');
print_r(date_get_last_errors());
?>
上面的例子会输出:
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引用发生错误的字符串中的字符索引。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com