time difference in HH:MM:SS format

后端 未结 2 916
庸人自扰
庸人自扰 2021-01-27 23:31

I want to get time difference in HH:MM:SS format below is the code

if time diff in seconds it should display l like 00:00:35 In minutes :00:30:35 In Hrs :01:30:35

2条回答
  •  时光取名叫无心
    2021-01-28 00:12

    You can use strtotime() for time calculation. Here is an example:

    $time1 = strtotime('10:55:59');
    $time2 = strtotime('10:56:00');
    $diff = $time2 - $time1;
    echo 'Time 1: '.date('H:i:s', $time1).'\n';
    echo 'Time 2: '.date('H:i:s', $time2).'\n'; if($diff){
    echo 'Diff: '.date('H:i:s', $diff);
    }else{
    echo 'No Diff.';
    }

    Output:

    Time 1: 09:00:59
    Time 2: 09:01:00
    Diff: 00:00:01

提交回复
热议问题