我怎么能从月份号码获得月份名称? [英] iphone how can i get month name from month number?
本文介绍了我怎么能从月份号码获得月份名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
iOS:如何从数字中获取正确的月份名称?
如何从月份号码获取月份名称?
How can I get month name from month number?
我有月份号码,如 02 ,但希望月份为字符串,在这种情况下 2月。
I have month number like 02, but would like the month as a string, in this case February.
推荐答案
这样的事情:
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);
这篇关于我怎么能从月份号码获得月份名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文