title: DateTimeFormatter Accepting Multiple Dates and Converting to One (java.time library)
body: <p>I am trying to write a <code>DateTimeFormatter</code> that will allow me to take in multiple different <code>String</code> formats, and then convert the <code>String</code> formats to a specific type. Due to the scope of the project and the code that already exists, I cannot use a different type of formatter.</p>
  
  <p>E.g., I want to accept <code>MM/dd/yyyy</code> as well as <code>yyyy-MM-dd'T'HH:mm:ss</code> but then when I print I only want to print to <code>MM/dd/yyyy</code> format and have it in the format when I call <code>LocalDate.format(formatter);</code></p>
  
  <p>Could someone suggest ideas on how to do this with the <code>java.time.format.*;</code></p>
  
  <p>Here is how I could do it in <code>org.joda</code>:</p>
  
  <pre><code>// MM/dd/yyyy format
  DateTimeFormatter monthDayYear = DateTimeFormat.forPattern("MM/dd/yyyy");
  // array of parsers, with all possible input patterns
  DateTimeParser[] parsers = {
          // parser for MM/dd/yyyy format
          monthDayYear.getParser(),
          // parser for yyyy-MM-dd'T'HH:mm:ss format
          DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss").getParser()
  };
  DateTimeFormatter parser = new DateTimeFormatterBuilder()
      // use the monthDayYear formatter for output (monthDayYear.getPrinter())
      // and parsers array for input (parsers)
      .append(monthDayYear.getPrinter(), parsers)
      // create formatter (using UTC to avoid DST problems)
      .toFormatter()
      .withZone(DateTimeZone.UTC);
  </code></pre>
  
  <p>I have not found a good/working example of this online.</p>