title: How to save current date and time to database using java?
body: <p>I am using the following code to get the current date and time, but the output is not what I am expecting and I cant save it into database.</p>
  
  <p>Output >> current: Tue Mar 05 09:58:26 EST 2013</p>
  
  <p>Expected output >> current: 2013-03-05 9:58:26</p>
  
  <pre><code> .....{  
          SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
          SimpleDateFormat parseFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
          Date date = new Date();
          try {
              System.out.println("current: " +parseFormat.parse(dateFormat.format(date)));
              return parseFormat.parse(dateFormat.format(date));
          } catch (ParseException ex) {
              Logger.getLogger(ConstructionModel.class.getName()).log(Level.SEVERE, null, ex);
          }
          return date;
       }
          ......
  
          ps.setDate(....) &lt;&lt;&lt; failed
  </code></pre>
  
  <p>Database </p>
  
  <pre><code> name   type
   mydate Date
  </code></pre>