How to convert a decimal into time, eg. HH:MM:SS

前端 未结 5 1059
栀梦
栀梦 2020-12-09 12:01

I am trying to take a decimal and convert it so that I can echo it as hours, minutes, and seconds.

I have the hours and minutes, but am breaking my brain trying to f

5条回答
  •  醉酒成梦
    2020-12-09 12:16

    Everything upvoted didnt work in my case. I have used that solution to convert decimal hours and minutes to normal time format. i.e.

    function clockalize($in){
    
        $h = intval($in);
        $m = round((((($in - $h) / 100.0) * 60.0) * 100), 0);
        if ($m == 60)
        {
            $h++;
            $m = 0;
        }
        $retval = sprintf("%02d:%02d", $h, $m);
        return $retval;
    }
    
    
    clockalize("17.5"); // 17:30
    

提交回复
热议问题