Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- echo 'event happened ' . humanTiming('2014-04-20 17:25:43') . ' ago';
- function humanTiming ($time)
- {
- $time = strtotime($time);
- $time = time() - $time;
- $tokens = array (
- 31536000 => 'year',
- 2592000 => 'month',
- 604800 => 'week',
- 86400 => 'day'
- );
- foreach ($tokens as $unit => $text) {
- if ($time < $unit) continue;
- $numberOfUnits = floor($time / $unit);
- return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement