I am having an issue converting a string to an NSDate in Swift. My date string is in the following format:
2016-05-06T14:07:23.430Z
I have a function to return a formatted date string as follows and the date string passed into the function is in the format shown above:
private func formatDate(theDate:String?) -> String {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM-dd-yy H:mm"
let actualDate = dateFormatter.dateFromString(theDate!) //always produces nil
let formattedDate = dateFormatter.stringFromDate(actualDate!)
return formattedDate
}
When trying to get a date object from the string passed into the function, the date object is always nil. Can anyone assist with this issue? Thanks!