PHP——秒转换为天 | 小时 | 分钟

前言

通讯记录需要用到的一个方法,记录下~

方法

/**
 * 秒转换为天,小时,分钟
 *
 * @param int $second
 *
 * @return string
 */
function secondConversion($second = 0)
{
    $newtime = '';
    $d = floor($second / (3600*24));
    $h = floor(($second % (3600*24)) / 3600);
    $m = floor((($second % (3600*24)) % 3600) / 60);
    if ($d>'0') {
        if ($h == '0' && $m == '0') {
            $newtime= $d.'天';
        } else {
            $newtime= $d.'天'.$h.'小时'.$m.'分';
        }
    } else {
        if ($h!='0') {
            if ($m == '0') {
                $newtime= $h.'小时';
            } else {
                $newtime= $h.'小时'.$m.'分';
            }
        } else {
            $newtime= $m.'分';
        }
    }
    return $newtime;
}

猜你喜欢

转载自www.cnblogs.com/wangyang0210/p/10789597.html