我使用以下代码尝试将数字月份 (5) 转换为全名 (May)。但是,当我将设置从 MM 更改为 MMMM 时,它只返回 null。为什么是这样?
NSDate *date = [birthday getDate];
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:date];
NSInteger year = [components year];
if (year == 1604) {
NSString *monthNumberString = [NSString stringWithFormat:@"%d", [components month]];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMMM"];
NSDate *date = [formatter dateFromString:monthNumberString];
NSString *stringFromDate = [formatter stringFromDate:date];
NSString *monthDay = [NSString stringWithFormat:@"%@, %d", stringFromDate, [components day]];
cell.birthdayLabel.text = monthDay;
} else {
...
}