title: Parse Date from String in this format : dd/MM/yyyy [to dd/MM/yyyy]
body: <p>I thinking what is the best way in Java to parse the String with this format
  dd/MM/yyyy [to dd/MM/yyyy]. The string with the [] are optional and dd stand for the 2 digit presentation of dates, MM is the 2 digit presentation of month and yyyy is the 4 digit presentation of year. </p>
  
  <hr>
  
  <p>Update</p>
  
  <p>Thanks guys for the fast response, however I forgot to tell you the [] is to symbolize optional, there is no [] in the string a sample String might be</p>
  
  <ul>
  <li>22/01/2010 </li>
  <li>22/01/2010 to 23/01/2010</li>
  <li>null </li>
  </ul>
  
  <p>Current I wrote the code this way, work but is ugly =(</p>
  
  <pre><code>String _daterange = (String) request.getParameter("daterange");
      Date startDate = null, endDate = null;
      // Format of incoming dateRange is 
      if (InputValidator.requiredValidator(_daterange)) {
          String[] _dateRanges = _daterange.toUpperCase().split("TO");
          try {
              startDate = (_dateRanges.length &gt; 0) ? sdf.parse(_dateRanges[0]) : null;
              try{
                  endDate = (_dateRanges.length &gt; 1) ? sdf.parse(_dateRanges[1]) : null;
              }catch(Exception e){
                  endDate = null;
              }
          } catch (Exception e) {
              startDate = null;
          }
      }
  </code></pre>