if (self.birthdate == nil) {
return nil;
}
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [gregorian components:NSYearCalendarUnit fromDate:self.birthdate toDate:[NSDate date] options:0];
NSInteger years = [components year];
return [NSNumber numberWithInteger:years];
计算年龄代码片段(根据出生日期计算年龄)
最新推荐文章于 2023-10-25 23:10:10 发布