NSDateFormatter return wrong date + Swift
I had the same problem and i this worked for me
You need to set the time zone
formatter.timeZone = NSTimeZone(abbreviation: "GMT+0:00")
When you convert from string to NSDate, if you do not set the timezone to the formatter, you will get the NSDate of a date in your local time zone. I suppose that your time zone is GMT+3 .
Then, when you show the value of 'date' (using println, NSLog but not NSDateFormatter), without setting the time zone, you will get GMT+0 time. That why you got 3h later.
Depend on how to use NSDateFormatter, you will have the date string as you want. In your case, It returns what you want, doesn't it?
Remember that NSDate presents a moment of time.
let dateString = "2016-04-02"
let formatter = NSDateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
println("dateString: \(dateString)")
formatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
let date = formatter.dateFromString(dateString) //without specify timezone, your dateString "2016-04-02" is your local time (GMT-3),
//means it's 2016-04-02 00:00:000 at GMT+0. That is the value that NSDate holds.
println("date: \(date)") //that why it show 2016-04-01 21:00:000, but not 2016-04-02 00:00:000
formatter.dateFormat = "yyyy-MM-dd"
let formattedDateString = formatter.stringFromDate(date!)
println("formattedDateString: \(formattedDateString)")