I have a UIDatePicker that shows (ex. April | 13 | 2010). I need to get each component value and set it as an integer so it can be put into three separate keys in a Plist.
MyMonth Number 04
MyDay Number 13
MyYear Number 2010
I can set a text label by using:
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateStyle = NSDateFormatterMediumStyle;
dateLabel.text = [NSString stringWithFormat:@"%@",
df stringFromDate:datePkr.date]];
[df release];
But I just need to convert each component value to integer. Would it be easier creating a UIPickerView with date array and doing it that way?
To get a component from date picker, generate a NSDateComponents object from the calendar with
-components:fromDate:
:NSDateComponents* comps = [datePkr.calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit)
fromDate:datePkr.date];
int myYear = [comps year];
int myMonth = [comps month];
int myDay = [comps day];
No comments:
Post a Comment