/** 从身份证上获取年龄 18位身份证 */ -(NSString *)getIdentityCardAge:(NSString *)numberStr { NSDateFormatter *formatterTow = [[NSDateFormatter alloc]init]; [formatterTow setDateFormat:@"yyyy-MM-dd"]; NSDate *bsyDate = [formatterTow dateFromString:[self birthdayStrFromIdentityCard:numberStr]]; NSTimeInterval dateDiff = [bsyDate timeIntervalSinceNow]; int age = trunc(dateDiff/(60*60*24))/365; return [NSString stringWithFormat:@"%d",-age]; } -(NSString *)birthdayStrFromIdentityCard:(NSString *)numberStr { NSMutableString *result = [NSMutableString stringWithCapacity:0]; NSString *year = nil; NSString *month = nil; BOOL isAllNumber = YES; NSString *day = nil; if([numberStr length]<18) return result; //**从第6位开始 截取8个数 NSString *fontNumer = [numberStr substringWithRange:NSMakeRange(6, 8)]; //**检测前12位否全都是数字; const char *str = [fontNumer UTF8String]; const char *p = str; while (*p!='