减去两次,总时数和工作时数


Substract two times, total hours and working hours

我想减去两个小时:

a。40:00:00b.31:18:00

我想要这个结果09:42:00。我怎样才能做到这一点?

结果是08:42:00(40:00:00-31:18:00=08:42:00而不是09:42:00)

我认为这解决了:

$lasthour = '40:00:00';
$firsthour =  '31:18:00';
//explode first hour
list($h, $m, $s) = explode(':', $firsthour);
//convert to seconds 
$secFh = ($h * 3600 + $m * 60 + $s);
//explode last hour
list($h, $m, $s) = explode(':', $lasthour);
//convert to seconds 
$secLh = ($h * 3600 + $m * 60 + $s);
$sub = $secLh - $secFh;
echo gmdate("H:i:s", $sub);