PHP计算小时数

Die*_*oP. 3 php

我有两个变量,例如:

$from = 13:43:13;

$to = 18:53:13;
Run Code Online (Sandbox Code Playgroud)

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

$total = 5.10 // 5 hours and ten minutes
Run Code Online (Sandbox Code Playgroud)

要么

$total = 0.40 // 0 hours and 40 minutes
Run Code Online (Sandbox Code Playgroud)

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

请帮我 :)

Pau*_*man 5

$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;
Run Code Online (Sandbox Code Playgroud)

  • 也可以根据您的行为方式来确定会议记录...... (2认同)