【发布时间】:2016-10-26 03:49:24
【问题描述】:
我试图找出两个日期之间的差异。不幸的是,我只得到整数,而不是按要求格式化。我尝试了几种方法,但没有运气。我需要从 $TactInterval 中扣除 $HoldInterval 但系统出错。 下面是我的代码,它不能按要求工作。 我收到 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>";
【问题讨论】:
标签: php date difference