title: DateTimeFormatterBuilder usages in Java 8, specifically optionals
body: <p>I'm trying to move from Joda to Java 8's <code>ZonedDateTime</code> and I'm hitting a wall with the <code>DateTimeFormatterBuilder</code> that I cannot seem to work around.</p>
  
  <p>I want to accept any of these formats:</p>
  
  <pre><code>2013-09-20T07:00:33
  2013-09-20T07:00:33.123
  2013-09-20T07:00:33.123+0000
  2013-09-20T07:00:33.123Z
  2013-09-20T07:00:33.123Z+0000
  2013-09-20T07:00:33+0000
  </code></pre>
  
  <p>Here is my current builder:</p>
  
  <pre><code>DateTimeFormatter formatter = new DateTimeFormatterBuilder()
          .parseCaseInsensitive()
          .append(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
          .optionalStart()
          .appendPattern(".SSS")
          .optionalEnd()
          .optionalStart()
          .appendZoneId()
          .optionalEnd()
          .optionalStart()
          .appendPattern("Z")
          .optionalEnd()
          .toFormatter();
  </code></pre>
  
  <p>I'm probably wrong, but it appears that should match the patterns I want... right?</p>
  
  <p>If anyone could point of what I may have missed, it'd be appreciated. I'm also not too sure of the use of <code>appendOffset</code>, so clarity on that is also appreciated if it turns out to be the answer.</p>
  
  <p><strong>Edit:</strong> </p>
  
  <pre><code>Text '2013-09-20T07:00:33.061+0000' could not be parsed at index 23
  </code></pre>
  
  <p>Looking at the builder, this appears to match due to the optional stages?</p>
  
  <p><strong>Edit 2:</strong></p>
  
  <p>After seeing advice from the first answer, I tried this:</p>
  
  <pre><code>DateTimeFormatter formatter = new DateTimeFormatterBuilder()
          .parseCaseInsensitive()
          .append(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
          .optionalStart()
          .appendPattern(".SSS")
          .optionalEnd()
          .optionalStart()
          .appendZoneOrOffsetId()
          .optionalEnd()
          .toFormatter()
  </code></pre>
  
  <p>It continues to fail on the string above.</p>
  
  <p><strong>Edit 3:</strong></p>
  
  <p>Latest tests result in this exception:</p>
  
  <pre><code>java.time.format.DateTimeParseException: Text '2013-09-20T07:00:33.061+0000' could not be parsed at index 23
  at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1947)
  at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1849)
  at java.time.ZonedDateTime.parse(ZonedDateTime.java:597)
  at java.time.ZonedDateTime.parse(ZonedDateTime.java:582)
  </code></pre>