title: MIlitary Time Validating
body: <p>I want to make sure that there are 5 characters in what the user inputs to change it to a military time and pretty much this is the format <code>##:##</code> (with the colon as well) and this is part of my code, but I cannot make it work.</p>
  
  <p>Any help will be great - thanks.</p>
  
  <pre><code>public Time(String militaryTime)
  {
      //Check to make sure something was entered
      if (militaryTime == null || !militaryTime.matches("^\\d{2}:\\d{2}$"))
      {
          System.out.println(
              "You must enter a valid miliary time." );
      }
      //Check to make sure there are 5  characters
      else
      {
          //Check to make sure the colon is in the right spot
  
          if (!Character.isDigit(militaryTime.charAt(2)))
          {
              System.out.println(militaryTime +
                  " is not a valid miliary time." );
          }
          //Check to make sure all other characters are digits
          else if (!Character.isDigit(militaryTime.charAt(0)))
          {
              System.out.println(militaryTime +
                  " is not a valid miliary time." );
          }
          else if (!Character.isDigit(militaryTime.charAt(0)))
          {
              System.out.println(militaryTime +
                  " is not a valid miliary time." );
          }
          else if (!Character.isDigit(militaryTime.charAt(0)))
          {
              System.out.println(militaryTime +
                  " is not a valid miliary time." );
          }
          else if (!Character.isDigit(militaryTime.charAt(0)))
          {
              System.out.println(militaryTime +
                  " is not a valid miliary time." );
          }
          else
          {
              //this separates hours and minutes
              hours = Integer.parseInt(militaryTime.substring(0,2));
  
              //validate hours and minutes are valid values
              if(hours &gt; 23)
              {
                  System.out.println(militaryTime +
                      " is not a valid miliary time." );
              }
              else if(minutes &gt; 59)
              {
                  System.out.println(militaryTime +
                      " is not a valid miliary time." );
              }
              //convert military time to conventional time
              //for afternoon times
              else if (hours &gt; 12)
              {
                  hours = hours - 12;
                  afternoon = true;
                  System.out.println(this.toString());
              }
              //account for midnight
              else if (hours == 0)
              {
                  hours = 12;
                  System.out.println(this.toString());
              }
              //account for noon
              else if (hours == 12)
              {
                  afternoon = true;
                  System.out.println(this.toString());
              }
              //morning times don't need converting
              else
              {
                  System.out.println(this.toString());
              }
          }
      }
  }
  </code></pre>