php計算時間幾分鐘前、幾小時前、幾天前的幾個函數

最新php計算時間幾分鐘前、幾小時前、幾天前的幾個函數php

如下是三零網爲你們整理的最新php計算時間幾分鐘前、幾小時前、幾天前的幾個函數的文章,但願你們可以喜歡!html


function time_tran($the_time) {  
    $now_time = date("Y-m-d H:i:s", time());  
    //echo $now_time;  
    $now_time = strtotime($now_time);  
    $show_time = strtotime($the_time);  
    $dur = $now_time - $show_time;  
    if ($dur < 0) {  
        return $the_time;  
    } else {  
        if ($dur < 60) {  
            return $dur . '秒前';  
        } else {  
            if ($dur < 3600) {  
                return floor($dur / 60) . '分鐘前';  
            } else {  
                if ($dur < 86400) {  
                    return floor($dur / 3600) . '小時前';  
                } else {  
                    if ($dur < 259200) {//3天內  
                        return floor($dur / 86400) . '天前';  
                    } else {  
                        return $the_time;  
                    }  
                }  
            }  
        }  
    }  

轉載來自:http://www.q3060.com/list3/list117/1.htmlide

相關文章
相關標籤/搜索