PHP DateTime: Failed to parse time string
I've looked at other questions about the same error but I'm having trouble applying them to my situation.
This is the error I'm getting:
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct() [datetime.--construct]: Failed to parse time string (2013-07-22164:50:00) at position 10 (1): Unexpected character' in /Applications/XAMPP/xamppfiles/htdocs/Festival_Planner/index.php:88 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/Festival_Planner/index.php(88): DateTime->__construct('2013-07-22164:5...', Object(DateTimeZone)) #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/Festival_Planner/index.php on line 88
This is the for loop with the line that's generating the error:
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);
}
And this is a similar for loop that DOES work, using exactly the same code structure as I did on line 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/69420.html
下一篇: PHP日期时间:解析时间字符串失败