PHP round time() up (future) to next multiple of 5 minutes

前端 未结 4 2009
陌清茗
陌清茗 2021-01-02 07:16

How do I round the result of time() up (towards the future) to the next multiple of 5 minutes?

4条回答
  •  滥情空心
    2021-01-02 07:50

    Try this function:

    function blockMinutesRound($hour, $minutes = '5', $format = "H:i") {
       $seconds = strtotime($hour);
       $rounded = round($seconds / ($minutes * 60)) * ($minutes * 60);
       return date($format, $rounded);
    }
    
    //call 
     blockMinutesRound('20:11');// return 20:10
    

提交回复
热议问题