[ create a new paste ] login | about

Link: http://codepad.org/YM9CeCSf    [ raw code | output | fork ]

balajimca - PHP, pasted on Sep 6:
<?php
//facebook like past time display
function facebook_style_date_time($timestamp){
$difference = time() - $timestamp;
$periods = array("sec", "min", "hour", "day", "week", "month", "years", "decade");
$lengths = array("60","60","24","7","4.35","12","10");

if ($difference > 0) { // this was in the past time
$ending = "ago";
} else { // this was in the future time
$difference = -$difference;
$ending = "to go";
}
for($j = 0; $difference >= $lengths[$j]; $j++) $difference /= $lengths[$j];
$difference = round($difference);
if($difference != 1) $periods[$j].= "s";
$text = "$difference $periods[$j] $ending";
return $text;
}

$my_time_stamp = "1346913040";
echo facebook_style_date_time($my_time_stamp);
echo "\n";
?>


Output:
1
5 mins ago


Create a new paste based on this one


Comments: