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

前端 未结 11 871
一向
一向 2020-11-30 22:43

I know that the NSDateformatter suite of functionality is a boon for mankind, but at the same time it is very confusing to me. I hope you can help me out.

Somewhere

11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 23:36

    Another option is to use the monthSymbols method:

    int monthNumber = 11;   //November
    NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
    NSString *monthName = [[df monthSymbols] objectAtIndex:(monthNumber-1)];
    

    Note that you'll need to subtract 1 from your 1..12 monthNumber since monthSymbols is zero-based.

提交回复
热议问题