帮助解决此错误
致命错误:消息'DateTime :: _ construct()[datetime .-- construct]的未捕获异常'Exception':无法解析位置0( - )处的时间字符串( - ):意外字符'在Z:\ home \ plati \ www \ view.php:110堆栈跟踪:#0 Z:\ home \ plati \ www \ view.php(110):DateTime-> _construct(' - ')在第110行的Z:\ home \ plati \ www \ view.php中抛出#1 {main}
$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');
答案 0 :(得分:4)
您是否尝试过打印"$newyear-$endmonth-$newday"
的值?因为从错误中看起来变量没有填充任何内容。所以请发布该字符串的结果。
答案 1 :(得分:1)
$ a中的值为空;检查你的输入。
答案 2 :(得分:1)
帮助解决此错误
您可以通过捕获它来轻松处理异常,这样可以解决错误,因为您不再需要为此错误烦恼:
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
抛出异常。