Getting MAX_INT from NSDateComponents
Posted
by MattyW
on Stack Overflow
See other posts from Stack Overflow
or by MattyW
Published on 2010-04-03T00:08:10Z
Indexed on
2010/04/03
0:13 UTC
Read the original article
Hit count: 181
I'm trying to write my first iPhone app, and I'm using a date picker object for the user to enter their date of birth. Part of my app requires the year in int format. I've added the code as below. What's odd is that 'month' gets the right value. But day and year seem to be stuck at MAX_INT (2147483647). Can anyone tell me what I'm 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];
}
© Stack Overflow or respective owner