title: Change the format of Date Java
body: <p>I've the Date object with the format </p>
  
  <pre><code> /107/2013 12:00:00 AM
  </code></pre>
  
  <p>Expected value for me: </p>
  
  <pre><code>2013-07-01
  </code></pre>
  
  <p>How I do this?. </p>
  
  <p>I'm trying with this code </p>
  
  <pre class="lang-java prettyprint-override"><code>public static  Date  formatearFecha( Date fecha ){
  
      String fechaString = new SimpleDateFormat("yyyy-MM-dd").format(fecha) ;
      DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
      Date fechaFormateada = null;
      try {
          fechaFormateada = df.parse(fechaString);
      } catch (ParseException ex) {
          Logger.getLogger(TestThings.class.getName()).log(Level.SEVERE, null, ex);
      }
      return fechaFormateada;
  
  }
  </code></pre>
  
  <p>When I try to make a test I get this:</p>
  
  <pre><code> System.out.println( formatearFecha(myDate) );
   Mon Sep 30 00:00:00 COT 2013
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>my problem was in sql change to java.util.Date to java.sql.Date<br>
  I solve this  so:</p>
  
  <pre class="lang-java prettyprint-override"><code>private  String formatearFecha( Date fecha ){
      return new SimpleDateFormat("yyyy-MM-dd").format(fecha);
  }
  
  private java.sql.Date stringToSQLDate( String fecString ){
  
      java.sql.Date fecFormatoDate = null;
      try {
            SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd", new Locale("es", "ES"));
           return  new java.sql.Date(sdf.parse(fecString).getTime());
      } catch (ParseException ex) { }
      return null;
  }
  </code></pre>
  
  <p>And test:
  </p>
  
  <pre><code>stringToSQLDate( formatearFecha( myDate ) );
  </code></pre>