title: Inserting date into SQL server from Java - not formatting properly
body: <p>I am trying to insert a date into a SQL table in a specific format. I am successfully inserting the date into a column of type <code>datetime</code>, but the formatting is incorrect. </p>
  
  <p>I have the following:</p>
  
  <pre><code>TimeZone tz = TimeZone.getTimeZone("UTC");
  DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  df.setTimeZone(tz);
  String timeString = df.format(System.currentTimeMillis());
  Date date = df.parse(timeString);
  java.sql.Date sqlDate = new java.sql.Date(date.getTime());
  </code></pre>
  
  <p>I can see that <code>timeString</code> is being set correctly to a string like : "<code>2017-01-11 18:19:06.662</code>"</p>
  
  <p>but date then gets set to something like: "<code>Wed Jan 11 13:19:06 EST 2017</code>" (missing milliseconds)</p>
  
  <p>and <code>sqlDate</code> gets set to "<code>2017-01-11</code>"</p>
  
  <p>when I look at the table to see what the value is, I see that for the field I'm setting, I'm seeing that the <code>datetime</code> gets set to "<code>2017-01-11 00:00:00.000</code>".</p>
  
  <p>Now this is missing all of the time info, which I'm sure has to do with the fact that <code>sqlDate</code> gets set to a value with no time, but Im not sure why sql date has no time value. I looked at some older posts that tried dealing with the same, but found no resolution <a href="https://stackoverflow.com/questions/29392755/how-to-convert-java-util-date-to-java-sql-date">here</a> or <a href="https://stackoverflow.com/questions/24320378/how-do-i-format-a-java-sql-date-into-this-format-mm-dd-yyyy">here</a>. </p>
  
  <p>Suggestions on why this may be happening are appreciated. </p>