Question

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?

Was it helpful?

Solution

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());
?>

OTHER TIPS

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 );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top