2011-06-25 139 views
0

什麼是以分鐘爲單位查找變量timeRemaining的正確方程式。查找剩餘時間

$lockDate = $row['lockDate']; 

       $currentDateTime = time(); 

       // Find out if user is locked out of their account 
       if (($lockDate != "0000-00-00 00:00:00") && strtotime($lockDate) < $currentDateTime) { 

        $lockDate = strtotime($lockDate); 
        $diff = $currentDateTime - $lockDate; 
        echo $diff; 

        // Take minutes and perform tasks 
        if ($diff <= 600) { 

         // Calculate time remaining 
         $timeRemaining = 10 - $diff; 

         // Account locked error 
         $errors = true; 
         $message = "Your account is currently locked, we appologize for the inconvienence. You must wait " .$timeRemaining." minutes before you can log in again!"; 

         $output = array('errorsExist' => $errors, 'message' => $message); 

        } else { 

         // Clear the lock 
         // $query = "UPDATE manager_users_hacking SET lockDate = NULL, hackerIPAddress = NULL, failedLogins = 0 WHERE userID = '".$userID."'"; 
         $result = mysqli_query($dbc,$query); 

        } 

       } 

回答

1

$ diff是以秒爲單位。您可以通過除以60來轉換爲分鐘。$ diff = $ diff/60。