Trying to get next twelve months of current year from current month. Below is my code i am trying, but it was picking from the next month, so i modified it but now it shows the current month for 2014 and others from 2013.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSDate *today = [NSDate date];
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
NSDateComponents *monthComponents = [currentCalendar components:NSMonthCalendarUnit fromDate:today];
int currentMonth = [monthComponents month];
NSDateComponents *yearComponents = [currentCalendar components:NSYearCalendarUnit fromDate:today];
int currentYear = [yearComponents year];
int nextYear = currentYear + 1;
int months = 1;
int year;
for(int m = currentMonth-1; months < 12; m++){
int nextMonth = m % 12;
if(nextMonth < currentMonth){
year = nextYear;
} else {
year = currentYear;
}
NSLog(@"%@ %i",[[dateFormatter monthSymbols] objectAtIndex: nextMonth],year);
months++;
}
This is the output from the link below.
August 2013
September 2013
October 2013
November 2013
December 2013
January 2014
February 2014
March 2014
April 2014
2013-07-09 12:54:48.683 MyEventApp[13562:c07] May 2014 2013-07-09 12:54:48.683 MyEventApp[13562:c07] June 2014 2013-07-09 12:54:48.683 MyEventApp[13562:c07] July 2014
Took help from this link Get Month and year of 1 year advance in iPhone.
This is from my modified code.
July 2014
August 2013
September 2013
October 2013
November 2013
December 2013
January 2014
February 2014
March 2014
April 2014
May 2014
June 2014