Milliseconds conversion to basic time

牧云@^-^@ 提交于 2019-12-11 06:23:11

问题


I need to convert 1774132 to 30:42 or 30 minutes and 42 seconds or whatever the output of this is. Is there any PHP function that does this?


回答1:


I found this online a long time ago, but I have no idea where from anymore:

<?php

function secondsToWords($seconds)
{
    /*** return value ***/
    $ret = "";

    /*** get the hours ***/
    $hours = intval(intval($seconds) / 3600);
    if($hours > 0)
    {
        $ret .= "$hours hours ";
    }
    /*** get the minutes ***/
    $minutes = bcmod((intval($seconds) / 60),60);
    if($hours > 0 || $minutes > 0)
    {
        $ret .= "$minutes minutes ";
    }

    /*** get the seconds ***/
    $seconds = bcmod(intval($seconds),60);
    $ret .= "$seconds seconds";

    return $ret;
}

echo secondsToWords(time());
?>



回答2:


Something like this should work:

printf("%d:%d:%d",$m / (1000*60*60), $m % (1000*60*60) / (1000*60),$m % (1000*60*60) % (1000*60) / 1000 );


来源:https://stackoverflow.com/questions/4798555/milliseconds-conversion-to-basic-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!