if (empty($krow['BUSSTRT'])){
$busts = $ts->add(new DateInterval('PT6i5s'));
$busDate = $busts->format('m/d/Y H:i:s');
echo "busDate:".$busDate."<br>\n";
}else{
$busts = new DateTime($krow['BUSSTRT']);
$busDate = $busts->format('m/d/Y H:i:s');
echo "busSTRT:".$busDate."<br>\n";
}
if (empty($krow['LAMISTRT'])){
echo "lamistrt is empty::::";
$lamts = $busts->add(new DateInterval('PT11is'));
$lamDate = $lamts->format('m/d/Y H:i:s');
echo "lamDate:".$lamDate."<br>\n";
}else{
$lamts = new DateTime($krow['LAMISTRT']);
$lamDate = $lamts->format('m/d/Y H:i:s');
echo "lamistrt:".$lamDate."<br>\n";
}
The code above is throwing the following error:
PHP Fatal error: Uncaught exception 'Exception' with message 'DateInterval::__construct(): Unknown or bad format (PT11i3s)'
when $bustDate
is:
busSTRT:02/06/2015 03:53:56 lamistrt is empty::::
What am I missing here?
When using DateInterval()
to create an interval you use M
for minutes, not i
. Also, if there are no seconds you must omit it from the interval declaration:
$busts = $ts->add(new DateInterval('PT6M5S'));
$lamts = $busts->add(new DateInterval('PT11M'));
i
is used for getting the number of minutes in a date interval:
echo $intervalObj->i; // get minutes
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.