thieumao

Get rest time in a week

Sep 29th, 2015
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.08 KB | None | 0 0
  1. <?php
  2. getRestTime();
  3.  
  4. function getRestTime(){
  5.     $TimePlay = getTime();
  6.     $day = $TimePlay[0];
  7.     $hour = $TimePlay[1];
  8.     $minute = $TimePlay[2];
  9.     $second = $TimePlay[3];
  10.    
  11.     $sumTimePlay = $day*24*60*60 +  $hour*60*60 + $minute*60 + $second;
  12.     $week = 7*24*60*60;
  13.    
  14.     $sumRestTime = $week - $sumTimePlay;
  15.    
  16.     $mod = $sumRestTime % (24*60*60);
  17.     $day = ($sumRestTime - $mod) / (24*60*60);
  18.    
  19.     $rest_time = $sumRestTime - $day * 24*60*60;
  20.     $mod = $rest_time % (60*60);
  21.     $hour = ($rest_time - $mod) / (60*60);
  22.    
  23.     $rest_time = $rest_time - $hour * 60*60;
  24.     $mod = $rest_time % 60;
  25.     $minute = ($rest_time - $mod) / 60;
  26.    
  27.     $second = $rest_time - $minute * 60;
  28.    
  29.     /*
  30.     $original_time_string = "2015-09-20 00:00:00";
  31.     $original_time = convert_datetime($original_time_string);
  32.     $now = time();
  33.     echo "<br>--------------<br>";
  34.     echo $original_time_string;
  35.     echo "<br>";
  36.     echo date('Y-m-d H:i:s', $now);
  37.     echo "<br>";
  38.     echo $day . " " . $hour . " " . $minute . " " . $second;   
  39.     */
  40.    
  41.     return array ($day, $hour, $minute, $second);
  42. }
  43.  
  44. function getTime(){
  45.     $original_time_string = "2015-09-20 00:00:00";
  46.     $original_time = convert_datetime($original_time_string);
  47.     $now = time();
  48.  
  49.     $rest_time = $now - $original_time;
  50.     $mod = $rest_time % (24*60*60);
  51.     $day = ($rest_time - $mod) / (24*60*60);
  52.  
  53.     $day2 = $day % 7;
  54.  
  55.     $rest_time = $rest_time - $day * 24*60*60;
  56.     $mod = $rest_time % (60*60);
  57.     $hour = ($rest_time - $mod) / (60*60);
  58.  
  59.     $rest_time = $rest_time - $hour * 60*60;
  60.     $mod = $rest_time % 60;
  61.     $minute = ($rest_time - $mod) / 60;
  62.  
  63.     $second = $rest_time - $minute * 60;
  64.    
  65.     /*
  66.     echo $original_time_string;
  67.     echo "<br>";
  68.     echo date('Y-m-d H:i:s', $now);
  69.     echo "<br>";
  70.     echo $day2 . " " . $hour . " " . $minute . " " . $second;  
  71.     */
  72.    
  73.     return array ($day2, $hour, $minute, $second);
  74.    
  75. }
  76.  
  77. function convert_datetime($str) {
  78.     list($date, $time) = explode(' ', $str);
  79.     list($year, $month, $day) = explode('-', $date);
  80.     list($hour, $minute, $second) = explode(':', $time);
  81.     $timestamp = mktime($hour, $minute, $second, $month, $day, $year);
  82.     return $timestamp;
  83. }
  84.  
  85. ?>
Advertisement
Add Comment
Please, Sign In to add comment