如何实现像时间戳差异功能的Facebook

时间:2011-09-03 08:41:41

标签: php timestamp

我正在使用php设计一个像时间戳差异函数的facebook,如下所示:

function time_parser($time)
    {

        if(!is_numeric($time))
        {
            $time = strtotime($time);
            if(!is_numeric($time))
            {
                return "";
            }
        }
        $difference = time() - $time;
        $periods = array("sec","min","hour","day","week","month","year");
        $lengths = array("60","60","24","7","4.35","12","10");

        if($difference > 0)
        {
            $ending = "ago";
        }
        else
        {
            $difference = -$difference;
            $ending = "to go";
        }
        for($j=0; $difference>=$lengths[$j] && $j<7;$j++)
        {
            $difference /= $lengths[$j];
        }
        $difference = round($difference);
        if($difference!=1)
        {
            $periods[$j].="s";
        }
                    $text = "$difference $periods[$j] $ending";
        return $text;
    }

现在的问题是,它会在一小时前的几小时内得出结果。怎么了 ?它取决于我的电脑的时区设置吗?

1 个答案:

答案 0 :(得分:0)