title: Date.toString() - sql vs util dates
body: <p>I need to remove time from a <code>Date</code> Object. Here is my try,</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>System.out.println("date " + dbDate);
  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
  System.out.println("formatter.format(dbDate) " + formatter.format(dbDate));
  System.out.println("final " + formatter.parse(formatter.format(dbDate)));
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>date 2011-12-03 23:59:59.0
  formatter.format(dbDate) 2011-12-03
  final Sat Dec 03 00:00:00 IST 2011
  </code></pre>
  
  <p>I want to the final date to display in <code>2011-12-03</code>. But after conversion <code>toString()</code> of that <code>Date</code> is in different format. I am missing something. Please help.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>In my application, I have two different methods to get <code>dbDate</code>. <code>EXPIRY_DATE</code> column is type of <code>DATE</code>.</p>
  
  <p>First query uses <code>dbDate = (java.util.Date) rs.getDate("EXPIRY_DATE");</code>. </p>
  
  <p>For this <code>dbDate</code>, <code>System.out.println("date " + dbDate);</code> gives <code>date 2011-12-03</code></p>
  
  <p>Second query uses <code>dbDate = rs.getTimestamp("EXPIRY_DATE");</code></p>
  
  <p>For this <code>dbDate</code>, <code>System.out.println("date " + dbDate);</code> gives <code>date 2011-12-03 23:59:59.0</code>.</p>
  
  <p>This is my problem. As I thought <code>toString()</code> was giving problem, I didn't mention the full problem.</p>
  
  <p><strong>Solution:</strong></p>
  
  <p>I did not have choices to avoid <code>java.sql.Date</code> as my application methods have multiple usages.
  I tried the below and worked,</p>
  
  <pre><code>dbDate = new java.sql.Date(dbDate.getTime());
  </code></pre>