123456789101112131415161718192021222324252627282930313233 |
- <?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';
- }
- }
- }
- }
|