PHP中的Twitter API格式"created_at"

Ant*_*ast -1 php twitter

我需要一个建议如何将Mon May 12 19:11:38 +0000 2014转换为2分钟前10分钟前.

我的编码是这样的.

if(isset($tweets->statuses) && is_array($tweets->statuses)) {
            if(count($tweets->statuses)) {
                foreach($tweets->statuses as $tweet) { 
                    echo "<td>";
                    echo $tweet->user->screen_name; 
                    echo "</td>"; 
                    echo "<td>";
                    echo $tweet->text;
                    echo "</td>";
                    echo "<td>";
                    echo $tweet->created_at;
                    echo "</td>";
                echo "</tr>";
Run Code Online (Sandbox Code Playgroud)

我已经实现了这样的东西,我想挖掘created_at它,因为它看起来有点奇怪.无论如何,我发现了许多像这样的来源.但那个不是我想要的.我要的是,使之出现像2 days ago,10 days ago,yesterday.任何的想法?

cmo*_*sey 5

这就是你要找的东西.

    function timeSince($time) {

        $since = time() - strtotime($time);

        $string     = '';

        $chunks = array(
            array(60 * 60 * 24 * 365 , 'year'),
            array(60 * 60 * 24 * 30 , 'month'),
            array(60 * 60 * 24 * 7, 'week'),
            array(60 * 60 * 24 , 'day'),
            array(60 * 60 , 'hour'),
            array(60 , 'minute'),
            array(1 , 'second')
        );

        for ($i = 0, $j = count($chunks); $i < $j; $i++) {
            $seconds = $chunks[$i][0];
            $name = $chunks[$i][1];
            if (($count = floor($since / $seconds)) != 0) {
                break;
            }
        }

        $string = ($count == 1) ? '1 ' . $name . ' ago' : $count . ' ' . $name . 's ago';

        return $string;

    }
Run Code Online (Sandbox Code Playgroud)