如何让总分钟数显示为 Xhrs、Xmin?
我正在花费总分钟数,并尝试计算总小时数和总小时数。分钟。
如果这样做:
$elapsed = "6476"; // Trying to get 107:56 (107 hours, 56 min)
if ($elapsed > 60) { $format = "i:s"; }
if ($elapsed > 3600) { $format = "H:i:s"; }
$showdiff = gmdate($format, $elapsed);
问题是它不适用于 23 小时 59 分钟以上的计算。
因此,您可以进行简单的除法:
$elapsed = $elapsed / 60; // total hours
只有这样您才会得到一个分数(在本例中为 107.933333333)。我需要将其保留为小时和分钟。有什么建议吗?
I'm taking a total number of minutes and am trying to calculate total hrs & minutes.
If you do:
$elapsed = "6476"; // Trying to get 107:56 (107 hours, 56 min)
if ($elapsed > 60) { $format = "i:s"; }
if ($elapsed > 3600) { $format = "H:i:s"; }
$showdiff = gmdate($format, $elapsed);
The problem with this is it doesn't work for calculations above 23hrs 59min.
So, you can do simple division:
$elapsed = $elapsed / 60; // total hours
Only then you will get a fraction (in this case, 107.933333333). I need to keep this as hours and minutes. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够使用除法(如您所述)和模除法来完成您想要的任务。
You should be able to use division (as you've stated) and modulus division to accomplish what you want.
你可以尝试一下
,也许可以写得更好一点,但我的借口是我累了:)
这应该会给你一个想法,让你做你需要做的事情。
you could try
probably could be written a bit better but my excuse is I'm tired :)
That should give you an idea though and let you do what you need to.