Advertisement
dangavin

Time Stuff

Oct 2nd, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1.         // This is here because I am showing the exact time of creation, is there a workaround?
  2.         if ( function_exists( 'date_default_timezone_set' ) )
  3.             date_default_timezone_set('America/Chicago'); //this overwrite all settings!!
  4.            
  5.         // It's sooner than 24 hours, so let's show a counter and expiration date
  6.         $time_left = $time - $one_day_ago;
  7.         $days_left = floor($time_left / 86400); // 86400 = seconds per day
  8.         $hours_left = floor(($time_left - $days_left * 86400) / 3600); // 3600 = seconds per hour
  9.         $mins_left = floor(($time_left - $days_left - $hours_left * 3600) / 60); // 60 = seconds per min
  10.         echo '<b>'.$entry["6.3"].' '.$entry["6.6"].'</b>';
  11.         echo '<br/>Created on: '.date_i18n('M d, Y h:i a', $time);
  12.         $total_time = strtotime($add_time, $time);
  13.         echo "<br/>$hours_left hours & $mins_left min remaining";
  14.         echo '<br/><i>This entry will be deleted on '.date_i18n('M d, Y h:i a', $total_time).'</i><br/><br/>';
  15.        
  16.         // This is here because I am showing the exact time of creation, is there a workaround?
  17.         // This resets the timezone, without this it messes up the counters...
  18.         if ( function_exists( 'date_default_timezone_set' ) )
  19.             date_default_timezone_set('UTC'); //this overwrite all settings!!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement