title: Java: Convert String to TimeStamp
body: <p>I have an issue while I try to convert a <code>String</code> to a <code>TimeStamp</code>. I have an array that has the date in the format of <code>yyyy-MM-dd</code> and I want to change it to the format of <code>yyyy-MM-dd HH:mm:ss.SSS</code>. So, I use this code:</p>
  <pre><code>final String OLD_FORMAT = &quot;yyyy-MM-dd&quot;;
  final String NEW_FORMAT = &quot;yyyy-MM-dd HH:mm:ss.SSS&quot;;
  String oldDateString = createdArray[k];
  String newDateString;
                  
  final DateFormat formatter = new SimpleDateFormat(OLD_FORMAT);
  final Date d = formatter.parse(oldDateString);
  ((SimpleDateFormat) formatter).applyPattern(NEW_FORMAT);
  newDateString = formatter.format(d);
  System.out.println(newDateString);
                  
  final Timestamp ts = Timestamp.valueOf(newDateString);
  System.out.println(ts);
  </code></pre>
  <p>and I get the following result.</p>
  <blockquote>
  <p>2009-10-20 00:00:00.000</p>
  <p>2009-10-20 00:00:00.0</p>
  </blockquote>
  <p>but when I try to simply do</p>
  <pre><code>final String text = &quot;2011-10-02 18:48:05.123&quot;;
  ts = Timestamp.valueOf(text);
  System.out.println(ts);
  </code></pre>
  <p>I get the right result:</p>
  <blockquote>
  <p>2011-10-02 18:48:05.123</p>
  </blockquote>
  <p>Do you know what I might be doing wrong?</p>
  <p>Thanks for the help.</p>