title: JDBC timestamp escape format and SimpleDateFormat in Java
body: <p>I'm trying to come up with <code>SimpleDateFormat</code> pattern to parse and format JDBC timestamps, in particular dates in the following format <code>yyyy-mm-dd hh:mm:ss.fffffffff</code>, where <code>ffffffffff</code> indicates nanoseconds. </p>
  
  <p>Unfortunately <code>new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss.SSS000000")</code> does not work, the following exception is thrown: </p>
  
  <pre><code>java.text.ParseException: Format.parseObject(String) failed
  </code></pre>
  
  <p>Is this possible with SimpleDateFormat at all, or I have to create a custom subclass of java.text.DateFormat to handle this case? <strong>Please note</strong> that it's not a question on how to parse <code>yyyy-mm-dd hh:mm:ss.fffffffff</code> string in Java, I'm interested in a declarative approach, i.e. SimpleDateFormat pattern which does not require additional modifications of the input string .</p>
  
  <p><strong>Example</strong>:</p>
  
  <p>I expect the input <code>2012-02-05 17:00:34.427000000</code>
  to be parsed as java.util.Date where milliseconds part is <code>427</code>.</p>
  
  <p>Here is a list of formats I've tried so far and they <em>all failed</em> for various reasons:</p>
  
  <ul>
  <li><code>new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss.SSS000000")</code> - <code>java.text.ParseException: Format.parseObject(String) failed</code></li>
  <li>Both <code>new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSSSSS", Locale.US)</code> and <code>new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US)</code> - are parsed as <em>Fri Feb 10 15:37:14</em> rather than expected one <em>Sun Feb 05 17:00:34</em>. (The nanoseconds part of <em>427000000</em> is treated as milliseconds, even if only SSS is specified)</li>
  </ul>