我试图添加php日期时间对象的差异,我做错了。我得到了我期望的时差:
$ total = 00:11:33 $ accumulator = 00:05:47
但是如何添加DateIntervals?或者我只是创建一个新的dateTime对象并添加到它?
$total = new DateInterval('P0000-00-00T00:00:00');
$accumulator = new DateInterval('P0000-00-00T00:00:00');
$a = new DateTime('2014-01-05 00:01:38');
$b = new DateTime('2014-01-05 00:13:11');
$c = new DateTime('2014-01-05 00:18:58');
$d = new DateTime('2014-01-05 00:24:45');
$total = $a->diff($b);
$accumulator = $c->diff($d);
echo '$total = ' . $total->format("%H:%I:%S");
echo '$accumulator = ' . $accumulator->format("%H:%I:%S");
$total += $accumulator;
echo 'Grand Total = ' . $total->format("%H:%I:%S");