Advertisement
cuonic

Untitled

Apr 21st, 2014
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. <?php
  2.  
  3. echo 'event happened ' . humanTiming('2010-04-28 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.         3600 => 'hour',
  16.         60 => 'minute',
  17.         1 => 'second');
  18.  
  19.     foreach ($tokens as $unit => $text) {
  20.         if ($time < $unit) continue;
  21.         $numberOfUnits = floor($time / $unit);
  22.         return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
  23.     }
  24. }
  25.  
  26. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement