Search code examples
stringdateswiftformatnsdate

From String to NSDate in Swift


I've got a string containing a date in this format: Thu, 04 Sep 2014 10:50:12 +0000

Do you know how can I convert it to: 04-09-2014 (dd-MM-yyyy)

of course, using Swift


Solution

  • If the above doesn't work, this should do the trick:

    let formatter = DateFormatter()
    formatter.locale = Locale(identifier: "US_en")
    formatter.dateFormat = "E, dd MMM yyyy HH:mm:ss Z"
    let date = formatter.date(from: "Thu, 04 Sep 2014 10:50:12 +0000")