PHP日期时间:解析时间字符串失败
我查看了其他有关同样错误的问题,但我无法将它们应用于我的情况。
这是我得到的错误:
致命错误:带有消息'DateTime :: __ construct()[日期时间.--构造]未捕获异常'异常':无法解析位置10(1)处的时间字符串(2013-07-22164:50:00):意外字符'in /Applications/XAMPP/xamppfiles/htdocs/Festival_Planner/index.php:88堆栈跟踪:#0 /Applications/XAMPP/xamppfiles/htdocs/Festival_Planner/index.php(88):DateTime - > __ construct('2013-07 -22164:5 ...',Object(DateTimeZone))#1 {main}抛出/ 88行/Applications/XAMPP/xamppfiles/htdocs/Festival_Planner/index.php
这是产生错误的行的for循环:
for($iCount2=0;$iCount2<count($ascreenings);$iCount2++){
$ocurrentscreening = $ascreenings[$iCount2];
///////// THIS IS LINE 88:
$time = new DateTime($ocurrentscreening->date.''.$ocurrentscreening->starttime,new DateTimeZone('Pacific/Auckland'));
$displayTime = date_format($time, 'g:ia');
$sLabel = $ocurrentscreening->date.', '.$displayTime.'.';
$oForm->makeCheckBox("screening".$ocurrentscreening->screeningid, $sLabel, $ocurrentscreening->screeningid);
}
这是一个类似的工作循环,使用与我在88行上完全相同的代码结构。
for($iCount=0;$iCount<count($aUsersScreenings);$iCount++){
$odisplayedscreening = $aUsersScreenings[$iCount];
$ofilm = new film();
$ofilm->load($odisplayedscreening->filmid);
$title = $ofilm->title;
$time = new DateTime($odisplayedscreening->date.''.$odisplayedscreening->starttime,new DateTimeZone('Pacific/Auckland'));
$displayTime = date_format($time, 'g:ia');
$sHTML .= '
<div class="selected" id="screening'.$odisplayedscreening->screeningid.'">
<span>'.$title.'</span>.'.$displayTime.'.
</div>
';
}
你需要在日期和时间之间有一个空间
$time = new DateTime($ocurrentscreening->date.' '.$ocurrentscreening->starttime,new DateTimeZone('Pacific/Auckland'));
链接地址: http://www.djcxy.com/p/69419.html