NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy";
NSDate *date = [dateFormatter dateFromString:@"2011"];
for(int month=0;month<=12;month++)
{
dateFormatter.dateFormat=@"MMMM";
NSString * monthString = [[dateFormatter stringFromDate:date] capitalizedString];
NSLog(@"month: %@", monthString);
}
I need to display the whole month in a particular year. For example, if I give a year like 2011, I want the whole 12-month year this year, I used this code above.
But the answer is, I get one month, like January, which is printed 12 times, but I need to get as much as 12 months in a particular year.
source
share