您好,欢迎来到要发发知识网。
搜索
您的当前位置:首页php中DateTime的错误处理

php中DateTime的错误处理

来源:要发发知识网

说明

1、DateTime对象可以过程化地写出来的。

2、提供了一种getLastErrors()方法,但是当使用面向对象的方法时,DateTime对象会以异常的形式被抛出。

实例

$date = date_create('asdfasdf');
print_r(DateTime::getLastErrors());
// 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
//         )
 
// )
 
try {
    $date = new DateTime('asdfasdf');
} catch (Exception $e) {
    echo $e->getMessage(), PHP_EOL;
}
// DateTime::__construct(): Failed to parse time string (asdfasdf) at position 0 (a): The timezone could not be found in the database

以上就是php中DateTime的错误处理,希望对大家有所帮助。更多php学习指路:

推荐操作系统:windows7系统、PHP5.6、DELL G3电脑

Copyright © 2019- net188.cn 版权所有 湘ICP备2022005869号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务