例如,如果我有:
$seconds = 3744000; // i want to output: 43 days, 8 hours, 0 minutes
Run Code Online (Sandbox Code Playgroud)
我是否必须创建一个函数来转换它?或者PHP已经内置了一些内容来做到这一点date()?
Ian*_*ory 19
function secondsToWords($seconds)
{
$ret = "";
/*** get the days ***/
$days = intval(intval($seconds) / (3600*24));
if($days> 0)
{
$ret .= "$days days ";
}
/*** get the hours ***/
$hours = (intval($seconds) / 3600) % 24;
if($hours > 0)
{
$ret .= "$hours hours ";
}
/*** get the minutes ***/
$minutes = (intval($seconds) / 60) % 60;
if($minutes > 0)
{
$ret .= "$minutes minutes ";
}
/*** get the seconds ***/
$seconds = intval($seconds) % 60;
if ($seconds > 0) {
$ret .= "$seconds seconds";
}
return $ret;
}
print secondsToWords(3744000);
Run Code Online (Sandbox Code Playgroud)