Converting NSDate to String using Swift 2.2

I recently had to convert NSDate to String and thought I’d post it here in case it helps someone else.

Let’s say you have a date created of: 2015-08-27 04:32:57 +0000

To return NSDate as String in the exact same format, use the code below:

let formatter = NSDateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss ZZZ"
formatter.timeZone = NSTimeZone(abbreviation: "UTC")
let dateCreated = formatter.stringFromDate(attributes[NSFileCreationDate] as! NSDate)

Hat tip to this StackOverflow answer.