php字符串时分秒转换为秒数,秒数转换为时分秒

163次阅读
没有评论
/*
* 秒数转换为时分秒
*/
function second_ctime($miao){$s=gmdate('H:i:s', $miao); //00:00:30
    $time = explode(':', $s);
    $time['0'] == '00' ? $h = 0 : $h = $time['0'];
    $time['1'] == '00' ? $m = 0 : $m = $time['1'];
    $time['2'] == '00' ? $s = 0 : $s = $time['2'];
    $ftime = (empty($h) ? (empty($m) ? $s .'秒' : (empty($s) ? $m . '分' : $m . '分' . $s .'秒')) :(empty($m) && empty($s) ? $h .'小时' : (empty($m)  ? $h . '时' . $s . '秒' : (empty($s) ? $h . '小时' . $m . '分' : $h . '小时' . $m . '分' .$s . '秒'))));
    return $ftime;
}
/*
* 包含时分秒的字符串,转换为秒数
*/
function second_statistics($strs){
    $minute=0;
    if($strs){$patterns = "/(\d+) 时 /";
        preg_match_all($patterns,$strs,$zzTime);
        $Time=isset($zzTime[1][0])?$zzTime[1][0]:0;
        $patterns = "/(\d+) 分 /";
        preg_match_all($patterns,$strs,$zzTimeFen);
        $TimeFen=isset($zzTimeFen[1][0])?$zzTimeFen[1][0]:0;
        $patterns = "/(\d+) 秒 /";
        preg_match_all($patterns,$strs,$zzTimeMiao);
        $TimeMiao=isset($zzTimeMiao[1][0])?$zzTimeMiao[1][0]:0;
        $minute=$Time*60*60+$TimeFen*60+$TimeMiao;
    }
    return $minute;
}

原文链接:https://blog.csdn.net/l2x1314258/article/details/108711489

正文完
有偿技术支持加微信
post-qrcode
 
评论(没有评论)
验证码