title: Java String to Date Conversion in different format
body: <p>So i have <code>String trDate="20120106";</code> and want to get <code>Date trDate=2012-01-06</code> and am trying to use <code>SimpleDateFormat</code> for changing the pattern but first i get to <code>parse</code> the string and then generate date and then try to call <code>format</code> which gives me back string but i need date, any suggestions, here is the code i have:</p>
  
  <pre><code>String trDate="20120106";    
  Date tradeDate = new SimpleDateFormat("yyyymmdd", Locale.ENGLISH).parse(trDate);
  String krwtrDate = new SimpleDateFormat("yyyy-mm-dd", Locale.ENGLISH).format(tradeDate);
  Date krwTradeDate = new SimpleDateFormat("yyyy-mm-dd", Locale.ENGLISH).parse(krwtrDate);
  </code></pre>
  
  <p>Here is <a href="https://stackoverflow.com/q/882420/164299">similar question</a> but it does not answer my question </p>
  
  <p>I need converted string in <code>Date format</code> only because i need to pass it to another function that expects <code>Date object</code> only.          </p>
  
  <p>Would really appreciate if someone can give example of how to get <code>date</code> in <code>yyyy-mm-dd</code> format from <code>string</code> which is in <code>yyyymmdd</code> format?</p>