Created
May 10, 2012 03:20
-
-
Save rambuvn/2650827 to your computer and use it in GitHub Desktop.
Time stamp ago function like facebook comment, post,...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function time_stamp($from){ | |
$cmt_date = $from; | |
$from = strtotime($from); | |
if ( empty($to) ) | |
$to = time(); | |
$diff = (int) abs($to - $from); | |
if($diff <= 1){ | |
$since = '1 second'; | |
} else if($diff <= 60 ){ | |
$since = sprintf(_n('%s second', '%s seconds', $diff), $diff); | |
} else if ($diff <= 3600) { | |
$mins = round($diff / 60); | |
if ($mins <= 1) { | |
$mins = 1; | |
} | |
/* translators: min=minute */ | |
$since = sprintf(_n('about %s min', '%s mins', $mins), $mins); | |
} else if ( ($diff <= 86400) && ($diff > 3600)) { | |
$hours = round($diff / 3600); | |
if ($hours <= 1) { | |
$hours = 1; | |
} | |
$since = sprintf(_n('about %s hour', '%s hours', $hours), $hours); | |
} elseif ($diff >= 86400 && $diff <= 86400*2 ) { | |
$days = round($diff / 86400); | |
if ($days <= 1) { | |
$days = 1; | |
} | |
$since = sprintf(_n('%s day', '%s days', $days), $days); | |
} else { | |
return date('M d \a\t h:i a',$from); | |
} | |
return $since . ' ago'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment