如何编写计算总工作时间的PHP代码?
例如:
工作时间开始:$starttime = 10:20
工作时间结束:“$stoptime = 12:59
总工作时间:$totaltime
应为:02:39
答案 0 :(得分:5)
使用此
<?php
$start = strtotime("12/12/2012 10:20:00");
$end = strtotime("12/12/2012 12:59:00");
$totaltime = ($end - $start) ;
$hours = intval($totaltime / 3600);
$seconds_remain = ($totaltime - ($hours * 3600));
$minutes = intval($seconds_remain / 60);
$seconds = ($seconds_remain - ($minutes * 60));
echo "$hours:$minutes:$seconds";
?>
答案 1 :(得分:3)
试试这段代码。
$starttime = '10:20';
$stoptime = '12:59';
$diff = (strtotime($stoptime) - strtotime($starttime));
$total = $diff/60;
echo sprintf("%02dh %02dm", floor($total/60), $total%60);