gpt4 book ai didi

PHP计算小时数

转载 作者:可可西里 更新时间:2023-11-01 00:24:48 24 4
gpt4 key购买 nike

我有两个变量,例如:

$from = 13:43:13;

$to = 18:53:13;

我需要用 PHP 计算 $from$to 之间的小时数,这样 $total 就像:

$total = 5.10 // 5 hours and ten minutes

$total = 0.40 // 0 hours and 40 minutes

我不介意秒,我需要的是小时和分钟。

请帮助我:)

最佳答案

$from       = '13:43:13';
$to = '18:53:13';

$total = strtotime($to) - strtotime($from);
$hours = floor($total / 60 / 60);
$minutes = round(($total - ($hours * 60 * 60)) / 60);

echo $hours.'.'.$minutes;

关于PHP计算小时数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9096090/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com