PHP round the time to the nearest 15 seconds

后端 未结 3 1773
遥遥无期
遥遥无期 2021-01-21 03:32

This is not a duplicate question, but involves a little understanding about time.

I need a solution to the following problem I have a number of specifically produced tim

3条回答
  •  长发绾君心
    2021-01-21 04:24

    $seconds = ($hr * 60 + $mn) * 60 + $sc; // convert to seconds
    $rounded = round($seconds/15)*15;       // round
    $sc = $rounded % 60;                    // get seconds
    $mn = ($rounded - $sc) / 60 % 60;       // get minutes
    $hr = ($rounded - $sc - $mn * 60) / 60; // get hours
    

提交回复
热议问题