iphone 如何从月份编号获取月份名称?

标签 iphone nsdate

Possible Duplicate:
iOS: How to get a proper Month name from a number?

如何从月份编号中获取月份名称?

我有像02这样的月份编号,但希望月份为字符串,在本例中为二月

最佳答案

类似这样的事情:

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

关于iphone 如何从月份编号获取月份名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4887712/

相关文章:

iphone - 异步下载图片

ios - 在 swift iOS 中获取 UTC 日期到本地日期

swift - 以正确的方式从 Int 构造日期

iphone - 显示按日期对核心数据进行排序

iphone - Objective-C : is it possible to detect QR code data type?

iphone - View Controller 未获取 -shouldAutorotateToInterfaceOrientation : messages on second load?

ios - iOS用户如何在卸载应用程序后删除钥匙串(keychain)

objective-c - objective-c 中的 GMT 时区转换

iphone - 如何在 iPhone objective-c 中显示昨天(相对于日期,但不是 24 小时的时间间隔)访问过的项目

ios - 从 NSDate 获取正确日期的问题