title: Date string to NSDate swift
body: <p>i'm having an array fill with date string, which i would like to go through and check whether the date is today or yesterday. The date string could look like following:</p>
  
  <pre><code>2015-04-10 22:07:00
  </code></pre>
  
  <p>So far i've tried just to convert it using dateFormatter, but it keeps returning nil</p>
  
  <pre><code>    var dateString = arrayNews[0][0].date as NSString
      var dateFormatter = NSDateFormatter()
      dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss"
  
      var date = dateFormatter.dateFromString(dateString as String)
      println(date)
  </code></pre>
  
  <p>the sudo code i would like to look something like this</p>
  
  <pre><code>if dateString == currentDate
      date = "Today, hh:mm"
  else if dateString == currentDate(-1)
      date = "Yesterday, hh:mm
  else
      date = dd. MM, hh:mm
  </code></pre>
  
  <p>in the else statement the date could be 1. April, 12:00</p>
  
  <p>How can i achieve such a logic?</p>
  
  <p><strong>Without the logic</strong></p>
  
  <pre><code>func getDate(dateStr:String, format:String = "yyyy-MM-dd HH:mm:ss") -&gt; NSString {
      var dateFmt = NSDateFormatter()
      dateFmt.timeZone = NSTimeZone.defaultTimeZone()
      dateFmt.dateFormat = format
      let newsDate = dateFmt.dateFromString(dateStr)!
  
      let date = NSDate();
      let dateFormatter = NSDateFormatter()
  
  
      dateFormatter.timeZone = NSTimeZone()
      let localDate = dateFormatter.stringFromDate(date)
  
  
      return ""
  }
  </code></pre>