title: Change date format in a Java string
body: <p>I've a <code>String</code> representing a date.</p>
  
  <pre><code>String date_s = "2011-01-18 00:00:00.0";
  </code></pre>
  
  <p>I'd like to convert it to a <code>Date</code> and output it in <code>YYYY-MM-DD</code> format.</p>
  
  <blockquote>
    <p>2011-01-18</p>
  </blockquote>
  
  <p>How can I achieve this?</p>
  
  <hr>
  
  <p>Okay, based on the answers I retrieved below, here's something I've tried:</p>
  
  <pre><code>String date_s = " 2011-01-18 00:00:00.0"; 
  SimpleDateFormat dt = new SimpleDateFormat("yyyyy-mm-dd hh:mm:ss"); 
  Date date = dt.parse(date_s); 
  SimpleDateFormat dt1 = new SimpleDateFormat("yyyyy-mm-dd");
  System.out.println(dt1.format(date));
  </code></pre>
  
  <p>But it outputs <code>02011-00-1</code> instead of the desired <code>2011-01-18</code>. What am I doing wrong?</p>