PHP时分秒转换为秒数

寻技术 PHP编程 / React 2023年07月08日 193
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;
}

$v_time_zhibo="00时21分20秒";
$v_time_zhibo_sec=second_statistics($v_time_zhibo);


关闭

用微信“扫一扫”