我只是想找出两次约会的区别。不幸的是,我只得到了整数,而没有按要求格式化。我试过几种方法,但没有运气。我需要从$HoldInterval中扣除$TactInterval,但系统出错了。下面是我的代码,它不能按要求工作。我得到的请求是2而不是02h30m。请告知问题所在。谢谢。
$hd1 = new Datetime('2016-10-18 08:30:00');
$hd2 = new Datetime('2016-10-18 12:00:00');
$HoldInterval = $hd2->diff($hd1);
$d1 = new Datetime('2016-10-18 09:00:00');
$d2 = new Datetime('2016-10-18 10:00:00');
$TactInterval = $d2->diff($d1);
//$interval = $TactInterval - $HoldInterval ); // This is not working....
$dt1 = $TactInterval->format('%Hh%Im');
$dt2 = $HoldInterval->format('%Hh%Im');
echo $dt1."<br>";
echo $dt2."<br>";
$dt3 = $dt2 - $dt1; // This is working but only a whole number shows. it show be 02h30m.
//$dt4 = $dt3->format('%Hh%Im'); // does not work when formated.
echo $dt3."<br>";发布于 2016-10-26 04:25:37
$s = new DateTime();
$e = new DateTime();
$s->add($HoldInterval);
$e->add($TactInterval);
$diff = $e->diff($s);
echo $diff->format('%Hh%Im');演示
https://stackoverflow.com/questions/40253416
复制相似问题