Check post "ago" time

This question already has an answer here:

  • Filter XML by elements [duplicate] 2 answers

  • Use this function:

    function humanTiming ($time) {
        $time = time() - $time;
        if ($time > 3600) {
            return date("y/m/d h/i", $time);
        }
        else {
            $tokens = array (
                31536000 => 'year',
                2592000 => 'month',
                604800 => 'week',
                86400 => 'day',
                3600 => 'hour',
                60 => 'minute',
                1 => 'second'
            );
            foreach ($tokens as $unit => $text) {
                if ($time < $unit) continue;
                $numberOfUnits = floor($time / $unit);
                return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
            }
        }
    }
    

    As you can see from the $tokens array, one hour is 3600 , so if time() - $time is more than that, then you merely need to return the date.


    There's a few great functions already on this site that should help:

  • PHP How to find the time elapsed since a date time?

  • date / time convert to time since php

  • PHP Time Since Function?

  • 链接地址: http://www.djcxy.com/p/58982.html

    上一篇: 将特定时间格式转换为PHP到MYSQL日期时间类型

    下一篇: 检查帖子“前”的时间