Age extracted from birth date always off by inconsistent amount
问题 I'm using the following code to convert a user-supplied birthdate to its equivalent years from the current date. The output is always off by an inconsistent amount in years and very large numbers in days and months. NSDateFormatter *tempFormatter = [[NSDateFormatter alloc] init]; [tempFormatter setDateFormat:@"yyyy-mm-dd hh:mm:ss"]; NSDate *birthDate = [tempFormatter dateFromString:[NSString stringWithFormat:@"%@-%@-%@ 01:00:00",self.birthYear.text,self.birthMonth.text,self.birthDay.text]];