title: Java: Parsing Date as String which may or may not contain timezone info
body: <p>Currently I am using below date parser to parse the date which is passed as <code>String</code>:</p>
  
  <pre><code>public static final DateTimeParser FRACTION_PARSER = new DateTimeFormatterBuilder()
  .appendLiteral('.').appendFractionOfSecond(0, 3).toParser();
  
  public static final DateTimeFormatter DATE_FORMATTER = new DateTimeFormatterBuilder()
  .appendPattern("yyyy-MM-dd'T'HH:mm:ss")
  .appendOptional(FRACTION_PARSER).appendLiteral('Z')
  .toFormatter();
  </code></pre>
  
  <p>And I have below conditions to parse:</p>
  
  <pre><code>public static void main(String[] args) {
      System.out.println(DATE_FORMATTER.parseDateTime("2016-01-13T13:38:19.679Z"));
      System.out.println(DATE_FORMATTER.parseDateTime("2016-01-13T13:38:19.67Z"));
      System.out.println(DATE_FORMATTER.parseDateTime("2016-01-13T13:38:19.6Z"));
      System.out.println(DATE_FORMATTER.parseDateTime("2016-01-13T13:38:19Z"));
      System.out.println(DATE_FORMATTER.parseDateTime("2016-01-15T16:58:57.649-05:00"));
  }
  </code></pre>
  
  <p>It parses the first four cases correctly but is failing for the last one with below error:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.IllegalArgumentException: Invalid format: "2016-01-15T16:58:57.649-05:00" is malformed at "-05:00"</p>
  </blockquote>
  
  <p>I understand its failinf as I appended literal <code>Z</code> to the format. But I was expecting it to work as a timeZone parser! </p>
  
  <p>Is there any simple way to use the same parser with optional parameter for all the above formats? or do I need to use different formats depending on the string that I get?</p>