开发者

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

开发者 https://www.devze.com 2023-02-08 03:25 出处:网络
This question already has answers here: Closed 12 years ago. 开发者_JAVA技巧 Possible Duplicate: iOS: How to get a proper Month name from a number?
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

精彩评论

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