1

I have this code to transform a string into a date:

extension String {
    func toDate(let format:String = "yyyy-MM-dd HH:mm", let timezone:NSTimeZone = NSTimeZone()) -> NSDate? {
        var formatter:NSDateFormatter = NSDateFormatter()
        formatter.locale = NSLocale.currentLocale()
        formatter.timeZone = timezone
        formatter.dateFormat = format
        return formatter.dateFromString(self)
    }
}

This works fine on 24hour mode on, but when i turn it off and i give it this string 2014-10-30 07:04, it always returns nil. Any idea why?

Dănuț Mihai Florian
  • 3,075
  • 3
  • 26
  • 44

0 Answers0