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

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

WBOY
Release: 2016-06-21 08:57:29
Original
1082 people have browsed it

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");
?>



Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template