NSDateFormatter returns 1970 instead of current year with format MM/dd
-
05-07-2019 - |
Question
The following code:
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"MM/dd"];
NSDate *newTime = [dateFormatter dateFromString:@"10/01"];
sets the resulting date to 10/01/1970. Is there a "right" way to have the formatter assume that you mean a date in the current year, or closest to the present date?
Solution
Did you try [dateFormatter setLenient:YES]
?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow