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

/*
*秒数转换为时分秒
*/
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;
}
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页