Possible Duplicate:
iOS: How to get a proper Month name from a number?
How can I get month name from month number?
I have month number like 02, but would like the month as a string, in this case February.
Something like this:
int monthNumber = 11;
NSString * dateString = [NSString stringWithFormat: @"%d", monthNumber];
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM"];
NSDate* myDate = [dateFormatter dateFromString:dateString];
[dateFormatter release];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMMM"];
NSString *stringFromDate = [formatter stringFromDate:myDate];
[formatter release];
NSLog(@"%@", stringFromDate);
You can use the monthSymbols array in NSDateFormatter, and then access that array by the key of the month number
精彩评论