Advertisement
cuonic

Untitled

Apr 21st, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.51 KB | None | 0 0
  1. <?php
  2.  
  3. echo 'event happened ' . humanTiming('2014-04-20 17:25:43') . ' ago';
  4.  
  5. function humanTiming ($time)
  6. {
  7.     $time = strtotime($time);
  8.     $time = time() - $time;
  9.  
  10.     $tokens = array (
  11.         31536000 => 'year',
  12.         2592000 => 'month',
  13.         604800 => 'week',
  14.         86400 => 'day'
  15.     );
  16.  
  17.     foreach ($tokens as $unit => $text) {
  18.         if ($time < $unit) continue;
  19.         $numberOfUnits = floor($time / $unit);
  20.         return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
  21.     }
  22. }
  23.  
  24. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement