2010-06-05 8 views
0

Dans un twitter Flux RSS pubDate est publié commeTwitter RSS pubDate Format

Sam 5 juin 2010 19:20

En utilisant PHP, ce qui est la meilleure façon de convertir cela en le temps lasped depuis publié . Pour eaxmple,

posté il y a 4 minutes posté il y a 1 heure posté il y a 4 heures Ajoutée il y a 1 jour posté 2 jours posté il y a 1 mois il y a posté 2 mois

vous aider beaucoup apprécié

Répondre

1
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';