title: i want to convert date fromat: "mm/dd/yyyy hh:mm" to "yyyy-mm-dd hh:mm:ss"
body: <p>Response from jsp is coming in this format: "mm/dd/yyyy hh:mm", and I want to convert to db format "yyyy-mm-dd hh:mm:ss".</p>
  
  <p>I tried this code :</p>
  
  <pre><code>public java.sql.Date getdateFormat(String datestring) throws ParseException {
      String datestr = "";
      try {
          java.util.Date date = new SimpleDateFormat("mm/dd/yyyy hh:mm a",
                  Locale.ENGLISH).parse(datestring);
          atestr = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(date);
      } catch (Exception e) {
          e.printStackTrace();
      }
      return getDateFromString(datestr);
  
  }
  
  
  public java.sql.Date getDateFromString(String string) {
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
      java.util.Date finalDate = null;
      try {
          finalDate = sdf.parse(string);
      } catch (Exception e) {
          e.printStackTrace();
      }
  
      return new java.sql.Date(finalDate.getTime());
  
  }
  </code></pre>