Created
October 27, 2015 11:16
-
-
Save DarkDust/5fbfafb3c9350b38666a to your computer and use it in GitHub Desktop.
Invalid date in NSDateFormatter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let formatter = NSDateFormatter() | |
formatter.dateFormat = "y-M-d" | |
formatter.timeZone = NSTimeZone(name: "America/Sao_Paulo") | |
let components = NSDateComponents() | |
components.day = 19 | |
components.month = 10 | |
components.year = 2015 | |
let date = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!.dateFromComponents(components) | |
let string = formatter.stringFromDate(date!) | |
do { | |
var result: AnyObject? | |
try formatter.getObjectValue(&result, forString: string, range: nil) | |
print(result) | |
} catch let error as NSError { | |
print(error) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment