title: Java date parsing with microsecond or nanosecond accuracy
body: <p>According to the <a href="http://docs.oracle.com/javase/8/docs/api/index.html?java/text/SimpleDateFormat.html" rel="noreferrer">SimpleDateFormat class documentation</a>, <code>Java</code> does not support time granularity above milliseconds in its date patterns.</p>
  
  <p>So, a date string like</p>
  
  <ul>
  <li>2015-05-09 00:10:23.999750900 // The last 9 digits denote nanoseconds</li>
  </ul>
  
  <p>when parsed via the pattern</p>
  
  <ul>
  <li>yyyy-MM-dd HH:mm:ss.SSSSSSSSS // 9 'S' symbols</li>
  </ul>
  
  <p>actually interprets the whole number after the <code>.</code> symbol as (nearly 1 billion!) milliseconds and not as nanoseconds, resulting in the date</p>
  
  <ul>
  <li>2015-05-20 21:52:53 UTC</li>
  </ul>
  
  <p>i.e. over 11 days ahead. Surprisingly, using a smaller number of <code>S</code> symbols still results in all 9 digits being parsed (instead of, say, the leftmost 3 for <code>.SSS</code>).</p>
  
  <p>There are 2 ways to handle this issue correctly:</p>
  
  <ul>
  <li>Use string preprocessing</li>
  <li>Use a custom SimpleDateFormat implementation</li>
  </ul>
  
  <p>Would there be any other way for getting a correct solution by just supplying a pattern to the standard <code>SimpleDateFormat</code> implementation, without any other code modifications or string manipulation?</p>