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

只谈情不闲聊 提交于 2019-12-20 17:32:14

问题


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.


回答1:


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);



回答2:


You can use the monthSymbols array in NSDateFormatter, and then access that array by the key of the month number



来源:https://stackoverflow.com/questions/4887712/iphone-how-can-i-get-month-name-from-month-number

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!