title: Java processing multiple possibly unknown date/time formats
body: <p>I am trying to create something that can check date/time of many formats to see if its a valid date/time so that I can process it.  Processing it consists of converting the date/time to something normalized for my software to work with.  The problem is that I would have to do a check in different ways to try and detect a date with SimpleDateFormat but it really has been hard to get every variety. The project is related to parsing CSV files with potentially user-specified date formats in a date column.  Is there a better way? Here is what I am doing right now:</p>
  
  <pre><code>public static boolean isDateValid(String dateString)
  {
      ArrayList&lt;SimpleDateFormat&gt; dateFormats = new ArrayList&lt;SimpleDateFormat&gt;();
  
      dateFormats.add(new SimpleDateFormat("M/dd/yyyy"));
      dateFormats.add(new SimpleDateFormat("dd.M.yyyy"));
      dateFormats.add(new SimpleDateFormat("M/dd/yyyy hh:mm:ss"));
      dateFormats.add(new SimpleDateFormat("dd.M.yyyy hh:mm:ss"));
      dateFormats.add(new SimpleDateFormat("dd-M-yyyy hh:mm:ss"));
      dateFormats.add(new SimpleDateFormat("M-dd-yyyy hh:mm:ss"));
      dateFormats.add(new SimpleDateFormat("yyyy-M-dd hh:mm:ss"));
      dateFormats.add(new SimpleDateFormat("dd.MMM.yyyy"));
      dateFormats.add(new SimpleDateFormat("dd-MMM-yyyy"));
      dateFormats.add(new SimpleDateFormat("M/dd"));
      dateFormats.add(new SimpleDateFormat("M dd"));
      dateFormats.add(new SimpleDateFormat("M y"));
      for (SimpleDateFormat format : dateFormats) 
      {
          try 
          {
              format.setLenient(false);
              Date date = format.parse(dateString);
              return true;
          } 
          catch (Exception e) 
          {
  
          }
      }
      return false;
  }
  </code></pre>
  
  <p>Additionally I have also tried using DateUtils from apache commons but it seems I would still have to cycle through a bunch of dates.</p>
  
  <pre><code>public static boolean isDate(String dateString)
  {
      try
      {
          Date theDate = DateUtils.parseDate(dateString);
      }
      catch (Exception e)
      {
          System.out.println(e);
          return false;
      }
      return true;
  }
  </code></pre>
  
  <p>Any ideas or words of encouragement?</p>