NsDate formatter giving wrong Date from String [duplicate]
问题 This question already has an answer here: NSDate Format outputting wrong date 5 answers I have the following code which takes a NSString and returns NSDate. I have copied this code from a project in which it runs perfectly fine - but some how this gives me the wrong output - (NSDate *)dateFromString:(NSString *)date { static NSDateFormatter *dateFormatter; if (!dateFormatter) { dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"dd-MM-yyyy"]; } NSLog(@"Date: %@