title: Java Date validation
body: <p>i need to validate user input as valid date. User can enter dd/mm/yyyy or mm/yyyy (both are valid)</p>
  
  <p>to validate this i was doing </p>
  
  <pre><code>try{
      GregorianCalendar cal = new GregorianCalendar(); 
      cal.setLenient(false);  
      String []userDate = uDate.split("/");
      if(userDate.length == 3){
          cal.set(Calendar.YEAR, Integer.parseInt(userDate[2]));  
          cal.set(Calendar.MONTH, Integer.parseInt(userDate[1]));  
          cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(userDate[0]));
          cal.getTime(); 
      }else if(userDate.length == 2){
          cal.set(Calendar.YEAR, Integer.parseInt(userDate[1]));  
          cal.set(Calendar.MONTH, Integer.parseInt(userDate[0]));  
          cal.getTime(); 
      }else{
              // invalid date
      }
  }catch(Exception e){
      //Invalid date
  }
  </code></pre>
  
  <p>as GregorianCalendar start month with 0, 30/01/2009 or 12/2009 gives error.</p>
  
  <p>any suggestion how to solve this issue.</p>