I have a unique requirement. In my app I need to get only the month from picker. Since Date picker cannot implement this, I made the custom picker listing only months. The required format of the date after the customer selects a month is 1-Jan-2011 to 1-feb-2011
Basically, the month is the only thing that is coming from uipickerview and the day and year are static.
Can someone help me out? Some code I have tried.
NSString *dateString = [[NSString alloc ]initWithFormat:@"2011-%d-1 GMT+05:30", monthFromPickerAsInteger];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// this is imporant - we set our input date format to match our input string
// if format doesn't match you'll get nil from your string, so be careful
[dateFormatter setDateFormat:@"yy-MM-DD z4"];
NSDate *dateFromString = [[NSDate alloc] init];
// ta-daaa!
dateFromString = [dateFormatter dateFromString:dateString];
NSLog(@"%@", dateFromString);
I guess you want to do this,