美文网首页
【PHP-日期和时间】时间差异计算函数

【PHP-日期和时间】时间差异计算函数

作者: SS_c2e5 | 来源:发表于2020-02-21 11:19 被阅读0次
    function ago($time)
    {
        $periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
        $lengths = array("60","60","24","7","4.35","12","10");
        $now = time();
        $difference = $now - $time;
        $tense = "ago";
        for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
            $difference /= $lengths[$j];
        }
        $difference = round($difference);
        if($difference != 1) {
            $periods[$j].= "s";
        }
        return "$difference $periods[$j] 'ago' ";
    }
    

    相关文章

      网友评论

          本文标题:【PHP-日期和时间】时间差异计算函数

          本文链接:https://www.haomeiwen.com/subject/iptcqhtx.html