title: How to create DateTimeformatter with optional seconds arguments
body: <p>I am trying to create a <code>DateTimeformatter</code> to validate following date times:</p>
  
  <pre><code>String date1 = "2017-07-06T17:25:28";
  String date2 = "2017-07-06T17:25:28.1";
  String date3 = "2017-07-06T17:25:28.12";
  String date4 = "2017-07-06T17:25:28.123";
  String date5 = "2017-07-06T17:25:28.1234";
  String date6 = "2017-07-06T17:25:28.12345";
  String date7 = "2017-07-06T17:25:28.123456";
  String date8 = "2017-07-06T17:25:28.";
  </code></pre>
  
  <p>I have tried the following date time formatter to validate above dates:</p>
  
  <pre><code>public static final String DATE_TIME_FORMAT_PATTERN = "yyyy-MM-dd'T'HH:mm:ss";
  DateTimeFormatter formatter1 = new DateTimeFormatterBuilder()
                                     .appendPattern(DATE_TIME_FORMAT_PATTERN)
                                     .appendFraction(ChronoField.MICRO_OF_SECOND, 0, 6, true)
                                     .toFormatter();
  </code></pre>
  
  <p>It works fine for all the above dates, but according to my requirement it should fail with <code>java.time.format.DateTimeParseException</code> for <code>date8</code>.</p>
  
  <p>Note: I am aware that I can achieve expected result with following formatter:</p>
  
  <pre><code>DateTimeFormatter formatter2 = DateTimeFormatter
                         .ofPattern("yyyy-MM-dd'T'HH:mm:ss[.SSSSSS][.SSSSS][.SSSS][.SSS][.SS][.S]");
  </code></pre>
  
  <p>But I wanted to know that can we achieve expected result by changing in <code>formatter1</code>?</p>
  
  <p>For parsing the date I am using following:</p>
  
  <pre><code>LocalDateTime.parse(date1, formatter1);
  </code></pre>