说明
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
推荐操作系统:windows7系统、PHP5.6、DELL G3电脑
关于“PHP中DateTime的错误处理是什么样的”的内容今天就到这,感谢各位的阅读,大家可以动手实际看看,对大家加深理解更有帮助哦。如果想了解更多相关内容的文章,关注我们,群英网络小编每天都会为大家更新不同的知识。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
长按识别二维码并关注微信
更方便到期提醒、手机管理