问题
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