php - Converting a unix time stamp to twitter/facebook style -



php - Converting a unix time stamp to twitter/facebook style -

i'm trying convert unix time stamp display facebook , twitter. example, when see tweets or comments placed on twitter/facebook see date/time displayed so:

'2 mins ago' or '2 days ago' or '2 weeks ago'

does 1 know of function working this. i'm guessing custom one.

any help much appreciated

if using php might want seek next function posted matt jones

http://www.mdj.us/web-development/php-programming/another-variation-on-the-time-ago-php-function-use-mysqls-datetime-field-type/

// displays comment post time "1 year, 1 week ago" or "5 minutes, 7 seconds ago", etc... function time_ago($date,$granularity=2) { $date = strtotime($date); $difference = time() - $date; $periods = array('decade' => 315360000, 'year' => 31536000, 'month' => 2628000, 'week' => 604800, 'day' => 86400, 'hour' => 3600, 'minute' => 60, 'second' => 1); foreach ($periods $key => $value) { if ($difference >= $value) { $time = floor($difference/$value); $difference %= $value; $retval .= ($retval ? ' ' : '').$time.' '; $retval .= (($time > 1) ? $key.'s' : $key); $granularity--; } if ($granularity == '0') { break; } } homecoming ' posted '.$retval.' ago'; }

php datetime timestamp unix-timestamp string-to-datetime

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -