1

我需要转换1774132为 30:42 或 30 分 42 秒或任何输出。是否有任何 PHP 函数可以做到这一点?

4

2 回答 2

2

我很久以前在网上找到了这个,但我不知道从哪里来:

<?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());
?>
于 2011-01-25T20:43:53.767 回答
1

像这样的东西应该工作:

printf("%d:%d:%d",$m / (1000*60*60), $m % (1000*60*60) / (1000*60),$m % (1000*60*60) % (1000*60) / 1000 );
于 2011-01-25T20:47:20.130 回答