致命错误:未捕获的异常“异常”有消息“日期时间::
问题描述:
帮助解决这个错误致命错误:未捕获的异常“异常”有消息“日期时间::
Fatal error: Uncaught exception 'Exception' with message 'DateTime::_construct() [datetime.--construct]: Failed to parse time string (--) at position 0 (-): Unexpected character' in Z:\home\plati\www\view.php:110 Stack trace: #0 Z:\home\plati\www\view.php(110): DateTime->_construct('--') #1 {main} thrown in Z:\home\plati\www\view.php on line 110
$newday = $a['dayz'];
$endmonth = $a['monthz'];
$newyear = $a['yearz'];
$date = new DateTime("$newyear-$endmonth-$newday");
$date->modify('+8 day');
$year = $date->format('Y');
$month = $date->format('m');
$day = $date->format('d');
答
help fix this error
您可以例外通过捕捉它轻松应对,这将解决在这个意义上的错误,你不必理会该错误不再:
try {
$newday = $a['dayz'];
$endmonth = $a['monthz'];
$newyear = $a['yearz'];
$date = new DateTime("$newyear-$endmonth-$newday");
$date->modify('+8 day');
$year = $date->format('Y');
$month = $date->format('m');
$day = $date->format('d');
} catch(Exception $e) {
# do nothing
}
至少在有一点你需要做错误处理。例外情况要求您这样做,DateTime
会引发异常。
答
你有没有试过打印值"$newyear-$endmonth-$newday"
?因为从错误,它看起来像变量没有填充任何内容。所以请发布该字符串的结果。
答
$ a中的值为空;检查你的输入。
oh yes $ a is empty tyvm – 2012-04-13 12:45:09