title: Set date format and then convert it in Date from String- Java
body: <p>I am doing this to set a date format and then convert it into date datatype but it is not giving expected results.</p>
  
  <pre><code> SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
   DateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
   String cur_date=dateFormat.format(new Date());
   myDb.setDOB(formatter.parse(cur_date));
  </code></pre>
  
  <p>Scenario is: I want  current date to be converted in yyyy/mm/dd and then pass it in setDOB(Date date). </p>
  
  <p><strong>EDIT:Result added</strong> Result is Tue Jan 01 00:08:00 IST 2013</p>
  
  <p>GUYS! I am not using 'mm',here I just mistakenly wrote mm in DateFormat it is also MM</p>
  
  <p><strong>EDIT AGAIN</strong> First I just used setDOB(new Date() ); but got formatting issue,</p>
  
  <p>then I used SimpleDateFormat.format to set yyyy/MM/dd but it returns String so used</p>
  
  <p>DateFormat.parse to convert it back into date type.</p>