I'm trying to parse a String in the format "ddMMyy-HH:mm:ss" using the following code
static func parseDate(var date: String?) -> NSDate?{
if(date == nil){
return nil
}
print("PARSING \(date)")
let formatter = NSDateFormatter()
formatter.dateFormat = "ddMMyy-HH:mm:ss"
let res = formatter.dateFromString(date!)
print("RESULT \(res)")
return res
}
The value of res is nil at the end, even though date is not nil. I then tried removing the : and - symbols using
date = date!.stringByReplacingOccurrencesOfString(":", withString: "")
date = date!.stringByReplacingOccurrencesOfString("-", withString: "")
And then changing my format to reflect this
formatter.dateFormat = "ddMMyyHHmmss"
The console output now is
TIME IS 291015-12:10:12
PARSING Optional("291015121012")
RESULT nil
I also tried adding the line
formatter.locale = NSLocale.currentLocale()
The strange thing is, the app works perfectly on iOS 9 and I think it worked on 8 too.