title: Catering for multiple date formats when converting date formats using Joda time
body: <p>Below code converts a date format from <code>"yyyy-MM-dd'T'HH:mm:ss"</code> to <code>"MM/dd/yyyy"</code> . </p>
  
  <pre><code>import org.joda.time.DateTime;
  import org.joda.time.format.DateTimeFormat;
  import org.joda.time.format.DateTimeFormatter;
  
  public class TestDate {
  
      public static void main(String[] args) {
  
          DateTimeFormatter parser = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss");
          DateTime dateTime = parser.parseDateTime("2014-05-19T23:59:59");
          DateTimeFormatter formatter = DateTimeFormat.forPattern("MM/dd/yyyy");
          System.out.println(formatter.print(dateTime)+"\n");
  
          dateTime = parser.parseDateTime("2014-06-09T03:00:23.67");
          formatter = DateTimeFormat.forPattern("MM/dd/yyyy");
          System.out.println(formatter.print(dateTime));
  
      }
  </code></pre>
  
  <p>An exception is thrown for <code>"2014-06-09T03:00:23.67"</code> : </p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: Invalid format: "2014-06-09T03:00:23.67" is malformed at ".67"
      at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:899)
      at TestDate.main(TestDate.java:16)
  </code></pre>
  
  <p>I need to be able to cater for other possibilities also such as : </p>
  
  <pre><code>2014-05-27T03:00:32.613
  </code></pre>
  
  <p>I just require the <code>"MM/dd/yyyy"</code> part of the date, everything subsequent to that can be ignored. Do I need to anticipate every date format explained at <a href="https://stackoverflow.com/questions/3307330/using-joda-date-time-api-to-parse-multiple-formats">Using Joda Date &amp; Time API to parse multiple formats</a></p>
  
  <p>Or can a wildcard be used which ignores everything after a certain pattern. Something like :        </p>
  
  <pre><code>DateTimeFormatter parser = DateTimeFormat.forPattern("yyyy-MM-dd%"); 
  </code></pre>
  
  <p>Or I could parse the string and split at the 'T' section of the date time, just using the value that appears before 'T', though this seems unclean....</p>
  
  <p>Or is there an alternative method ?</p>
  
  <p>Update : </p>
  
  <p>Since time is not required, instead of using :</p>
  
  <pre><code>String strDate = "2014-05-19T23:59:59";
  DateTime dateTime = parser.parseDateTime(strDate);
  </code></pre>
  
  <p>will use : </p>
  
  <pre><code>String strDate = "2014-05-19T23:59:59";
  DateTime dateTime = parser.parseDateTime(strDate.substring(0, 10));
  </code></pre>
  
  <p>Which will just parse <code>2014-05-19</code> part of String, this will cater for multiple time formats. </p>