ID: 41ff87ec464267a2f322d6c6dbc888f116d56718
32 lines
—
817B —
View raw
| <?php
class Date
{
public static function ago ($datetime)
{
$estimate_time = time() - $datetime;
if( $estimate_time < 1 )
return 'right now';
$condition = array(
12 * 30 * 24 * 60 * 60 => 'year',
30 * 24 * 60 * 60 => 'month',
24 * 60 * 60 => 'day',
60 * 60 => 'hour',
60 => 'minute',
1 => 'second');
foreach ($condition as $secs => $str)
{
$d = $estimate_time / $secs;
if ($d >= 1)
{
$r = round ($d);
return $r . ' ' . $str . ($r > 1 ? 's' : '') . ' ago';
}
}
}
}
|