I am trying to write my first iPhone app, and I am using a date picker so that the user can enter their date of birth. Part of my application requires a year in int format. I have added the code as shown below. What is strange is that the "month" gets the correct value. But the day and year seem to be stuck in MAX_INT (2147483647). Can someone tell me what I am doing wrong?
-(IBAction)dateOfBirthChanged:(id)sender { NSCalendar* calender = [NSCalendar currentCalendar]; NSDateComponents* dateComponents = [calender components:NSMonthCalendarUnit fromDate:[datepicker date]]; NSInteger day = [dateComponents day]; NSInteger month = [dateComponents month]; NSInteger year = [dateComponents year]; label.text = [NSString stringWithFormat:@"Your year of birth is %d", year]; }
source share