Php Twitter RSS发布日期格式

Php Twitter RSS发布日期格式,php,rss,twitter,pubdate,Php,Rss,Twitter,Pubdate,在twitter RSS提要中,pubDate发布为 2010年6月5日星期六19:20 使用PHP,将其转换为自发布以来的时间的最佳方法是什么。例如 4分钟前发的 一小时前发的 4小时前贴的 一天前发布 2天前发布 一个月前发布 2个月前发布 您的帮助非常受欢迎在多长时间前($unixTime)起作用{ function how_long_ago($unixTime) { $chunks = array( array(60 * 60 * 24 * 365 , 'year

在twitter RSS提要中,pubDate发布为

2010年6月5日星期六19:20

使用PHP,将其转换为自发布以来的时间的最佳方法是什么。例如

4分钟前发的 一小时前发的 4小时前贴的 一天前发布 2天前发布 一个月前发布 2个月前发布

您的帮助非常受欢迎

在多长时间前($unixTime)起作用{
function how_long_ago($unixTime) {
    $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'),
    );
    $today = time();
    $since = $today - $unixTime;
    for ($i = 0, $j = count($chunks); $i < $j; $i++) {
        $seconds = $chunks[$i][0];
        $name = $chunks[$i][1];
        if (($count = floor($since / $seconds)) != 0) {
            break;
        }
    }
    return $count == 1 ? '1 '.$name : "$count {$name}s";
}

$rssUnixTime = strtotime('Sat, Jun 5, 2010 19:20');
echo 'posted '.how_long_ago($rssUnixTime).' ago';
$chunks=数组( 阵列(60*60*24*365,'年'), 数组(60*60*24*30,'月'), 数组(60*60*24*7,'周'), 数组(60*60*24,'天'), 数组(60*60,'小时'), 数组(60,'分钟'), ); $today=时间(); $since=$today-$unixTime; 对于($i=0,$j=count($chunks);$i<$j;$i++){ $seconds=$chunks[$i][0]; $name=$chunks[$i][1]; 如果(($count=floor($since/$seconds))!=0){ 打破 } } 返回$count==1?'1'。$name:“$count{$name}s”; } $rssUnixTime=strotime('2010年6月5日星期六19:20'); echo“已发布”。多久以前($rssUnixTime)。“以前”;