2011-06-25 141 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。