微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 致命错误:未捕获的异常’Exception’,消息’DateTime ::

帮助解决错误

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抛出异常.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐