0

I'm trying to use NSDateFormatter to get the NSDate from String.

I've got the date in this format "Sat, 01 Aug 2015 15:00:12 GMT" and I'm setting date format this way:

dateFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss Z"

but dateFormatter.dateFromString("Sat, 01 Aug 2015 15:00:12 GMT") returns nil. Why is that happening and how to fix it?

EDIT:

var date:NSDate? let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss z" date = dateFormatter.dateFromString("Sat, 01 Aug 2015 15:00:12 GMT")

Andrii Liakh
  • 619
  • 3
  • 16
  • 1
    As explained in the referenced thread, you have to set the date formatters locale to "en_US_POSIX". See also [What is the best way to deal with the NSDateFormatter locale “feature”?](http://stackoverflow.com/questions/6613110/what-is-the-best-way-to-deal-with-the-nsdateformatter-locale-feature) and [Technical Q&A QA1480 NSDateFormatter and Internet Dates](https://developer.apple.com/library/ios/qa/qa1480/_index.html). – Martin R Aug 01 '15 at 16:42
  • 1
    I verified that before closing the question as a duplicate :) – Martin R Aug 01 '15 at 16:46

0 Answers0