title: swift - Convert a String to a Date and then to a String in a different format
body: <p>Suppose I have a simple String, extracted from an array of strings (representing dates) -</p>
  
  <pre><code>var myDateString = "2015-11-25 04:31:32.0"
  </code></pre>
  
  <p>Now, I want to convert it to a string that looks like <strong>Nov 25, 2015</strong>.</p>
  
  <p>For that, I assume I need to -</p>
  
  <ul>
  <li>get a NSDate date object from string using NSDateFormatter</li>
  <li>get a string from that NSDate object by using some functionality (which I've been unable to find)</li>
  </ul>
  
  <p>I've been trying this in Playground, but have been unable to solve such a simple problem.</p>
  
  <p>Here is what I have tried - </p>
  
  <pre><code>Line 1| var dateFormatter = NSDateFormatter()
  Line 2| dateFormatter.locale = NSLocale.currentLocale()
  Line 3| dateFormatter.dateFormat = "YYYY-MM-dd HH:mm:ss.A"
  Line 4| let somedate = dateFormatter.dateFromString(str)
  Line 5| let somedateString = dateFormatter.stringFromDate(somedate!)
  </code></pre>
  
  <p>In the sidebar of Xcode, line 4 prints <code>"Nov 25, 2015, 12:00 AM"</code>, but when I try to print a string from <code>somedate</code>, I get <code>"2015-11-25 00:00:00.0"</code>.</p>
  
  <p>I haven't found a single proper explanation of NSDates anywhere.</p>
  
  <p>This was so much easier in Java with <code>parse()</code> and <code>format()</code> functions for Dates. </p>