PHP计算总时间 [英] PHP Calculate total time

查看:88
本文介绍了PHP计算总时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何编写一个计算总工作时间的PHP代码?

How can I write a PHP code that calculates the total working time?

例如:

上班时间:$starttime = 10:20
工作时间结束:"$stoptime = 12:59

Start of working time: $starttime = 10:20
End of working time:"$stoptime = 12:59

因此总工作时间:$totaltime应该是:02:39

So Total working time: $totaltime should be: 02:39

推荐答案

尝试以下代码.

    $starttime = '10:20';
    $stoptime = '12:59';
    $diff = (strtotime($stoptime) - strtotime($starttime));
    $total = $diff/60;
    echo sprintf("%02dh %02dm", floor($total/60), $total%60);

这篇关于PHP计算总时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆