\你必须检查你的要求。
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"dd-MMM-yyyy"];
NSDate *date1 = [formatter dateFromString:@"11-jan-2012"];
NSDate *date2 = [formatter dateFromString:@"15-jan-2012"];
NSDateComponents *dateComponents;
dateComponents = [[NSCalendar currentCalendar] components:NSYearCalendarUnit |NSDayCalendarUnit | NSMonthCalendarUnit
fromDate:date1];
int day1 = [dateComponents day];
int month1 = [dateComponents month];
int year1 = [dateComponents year];
dateComponents = [[NSCalendar currentCalendar] components:NSYearCalendarUnit |NSDayCalendarUnit | NSMonthCalendarUnit
fromDate:date2];
int day2 = [dateComponents day];
int month2 = [dateComponents month];
int year2 = [dateComponents year];
NSString *str = [NSString stringWithFormat:@"%d - %d %d %d", day1, day2, month1, year1];
您必须根据您的要求检查月份和年份。