开发者

iphone how can i get month name from month number? [duplicate]

This question already has answers here: Closed 12 years ago. 开发者_JAVA技巧

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜