Home >php教程 >php手册 >php显示文章发表于某月某天某小时和分钟前的函数

php显示文章发表于某月某天某小时和分钟前的函数

WBOY
WBOYOriginal
2016-06-21 08:57:291063browse

php显示文章发表于某月某天某小时和分钟前的函数


function format_date($dateStr) {
    $limit = time() - strtotime($dateStr);
    $r = "";
    if($limit 60) {
        $r = '刚刚';
    } elseif($limit >= 60 && $limit 3600) {
        $r = floor($limit / 60)  .  '分钟前';
    } elseif($limit >= 3600 && $limit 86400) {
       $r = floor($limit / 3600)  .  '小时前';
    } elseif($limit >= 86400 && $limit 2592000) {
        $r = floor($limit / 86400)  .  '天前';
    } elseif($limit >= 2592000 && $limit 31104000) {
        $r = floor($limit / 2592000)  .  '个月前';
    } else {
        $r = "很久前";
    }
    return $r . "(" . $dateStr . ")";
}

echo "发表于:" . format_date("2009-02-15 18:10");
?>



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn