509
说明
1、DateTime对象可以过程化地写出来的。
2、提供了一种getLastErrors()方法,但是当使用面向对象的方法时,DateTime对象会以异常的形式被抛出。
实例
$date=date_create('asdfasdf');
print_r(DateTime::getLastErrors());
//Array
//(
//[warning_count]=>1
//[warnings]=>Array
//(
//[6]=>Doubletimezonespecification
//)
//[error_count]=>1
//[errors]=>Array
//(
//[0]=>Thetimezonecouldnotbefoundinthedatabase
//)
//)
try{
$date=newDateTime('asdfasdf');
catch(Exception$e){
echo$e->getMessage(),PHP_EOL;
//DateTime::__construct():Failedtoparsetimestring(asdfasdf)atposition0(a):Thetimezonecouldnotbefoundinthedatabase
以上就是php中DateTime的错误处理,希望对大家有所帮助。更多php学习指路:php教程