PHP 把秒转换成时分秒(00:00:00)格式

/**
 *  把秒数转换为时分秒(00:00:00)的格式
 *  @param Int $times 时间,单位(秒)
 *  @return String
 */
function secondToTime($times){
    $result = '00:00:00';
    if ($times>0) {
        $hour = floor($times/3600);
        $minute = floor(($times-3600 * $hour)/60);
        $second = floor((($times-3600 * $hour) - 60 * $minute) % 60);
        $hour = $hour < 10 ? '0'.$hour : $hour;
        $minute = $minute < 10 ? '0'.$minute : $minute;
        $second = $second < 10 ? '0'.$second : $second;
        $result = $hour.':'.$minute.':'.$second;
    }
    return $result;
}

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注