title: Java 8: How to create DateTimeFormatter with milli, micro or nano seconds?
body: <p>I need to create the formatter for parsing timestamps with optional milli, micro or nano fractions of second.</p>
  
  <p>For example, for my needs I see the following opportunity:</p>
  
  <pre><code>DateTimeFormatter formatter = new DateTimeFormatterBuilder()
                                     .append(DateTimeFormatter.BASIC_ISO_DATE)
                                     .appendLiteral('-')
                                     .append(DateTimeFormatter.ISO_LOCAL_TIME)
                                     .appendOffset("+HH:mm", "Z")
                                     .toFormatter();
  </code></pre>
  
  <p>Or it is also possible to use <code>appendFraction(field, minWidth, maxWidth, decimalPoint)</code>.</p>
  
  <p>However in these cases will it be possible to parse timestamps with any number of decimals (up to 9 or maxWidth). How to achieve that we can parse (optionally) only 3, 6 or 9 numbers after the comma?</p>
  
  <p>It should be possible to parse the following time parts:</p>
  
  <ul>
  <li><code>HH:mm:ss.SSS</code></li>
  <li><code>HH:mm:ss.SSSSSS</code></li>
  <li><code>HH:mm:ss.SSSSSSSSS</code></li>
  </ul>
  
  <p>But impossible to parse: <code>HH:mm:ss.SSSS</code>.</p>