This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

function niceTime

By: a guest on Oct 28th, 2010  |  syntax: PHP  |  size: 0.65 KB  |  views: 670  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. function niceTime( $time )
  4. {
  5.         $time = strtotime( str_replace( '+0000', '', $time ) );
  6.        
  7.         $delta = time() - $time;
  8.        
  9.         switch( $delta )
  10.         {
  11.                 case ( $delta < 60 ):
  12.                         return 'less than a minute ago.';
  13.                 case( $delta < 120 ):
  14.                         return 'about a minute ago.';
  15.                 case( $delta < ( 45 * 60 ) ):
  16.                         return floor( $delta / 60 ) . ' minutes ago.';
  17.                 case( $delta < ( 90 * 60 ) ):
  18.                         return 'about an hour ago.';
  19.                 case( $delta < ( 24 * 60 * 60 ) ):
  20.                         return 'about ' . floor( $delta / 3600 ) . ' hours ago.';
  21.                 case( $delta < ( 48 * 60 * 60 ) ):
  22.                         return '1 day ago.';
  23.                 default:
  24.                         return floor( $delta / 86400 ) . ' days ago.';
  25.         }
  26. }
  27.  
  28. ?>
clone this paste RAW Paste Data