title: How to convert String input with milliseconds to Date
body: <p>I have a java method which needs to convert a Date from one input String format to another.  The input and output formats must retain all millisecond detail, as this is for a process tracking solution where timestamps will often be just milliseconds apart.</p>
  
  <p>The SimpleDateFormat seems to be losing all millisecond data, and just returning random numbers for the seconds and milliseconds.</p>
  
  <p>input date String: "05/23/2013 12:32:13.45133"
  input date format: "MM/dd/yyyy HH:mm:ss.SSSSS"
  output date format: "yyyyMMddHHmmssSSS"</p>
  
  <p>Given the above input date and format, my resulting Date String is: 20130523123258133.  This is obviously completely off from the input seconds.</p>
  
  <p>The input format may vary, but the output format must always be the same.</p>
  
  <p>Below is the current method:</p>
  
  <pre><code>private long dateSequencer(String inputDt, String inputFormat) {
      long result = 0;
      try {
          // Convert input date into yyyyMMddHHmmssSSS format for sequencing
          SimpleDateFormat dtFrmt = new SimpleDateFormat(inputFormat);
          Date dt = new Date();
          dt = dtFrmt.parse(inputDt);
          // input String converted to Date, now reformat to Long
          dtFrmt = new SimpleDateFormat("yyyyMMddHHmmssSSS");
          String reFrmt = dtFrmt.format(dt);
          result = Long.parseLong(reFrmt);
      } catch (Exception ex) {
          System.out.println("++++ Exception converting dateSequencer: " + ex.toString());
      }
      System.out.print("+++ABM dateSeq: [inputDt=" + inputDt + "] [inputFormat=" + inputFormat + "] [result=" + result +"]");
      return result;
  }
  </code></pre>
  
  <p>Log file entry from runtime:</p>
  
  <pre>
  +++ABM dateSeq: [inputDt=05/23/2013 12:32:13.45133] [inputFormat=MM/dd/yyyy HH:mm:ss.SSSSS] [result=20130523123258133]
  </pre>
  
  <p>Since the input format may change, I cannot manually parse the input String to rely on a specific pattern.  This is why I am allowing the pattern to be passed, and using a SimpleDateFormat to convert to Date, then back to String.</p>
  
  <p>How can I do this, reliably?  Is there a more efficient way to convert a given input Date string, to a standard format?</p>
  
  <p>Thanks!</p>