Wednesday, 9 July 2014

How to get next year from the current date or selected date


 you can do the following:

1)     NSDate *today = [NSDate date]; // get the current date
        NSCalendar* cal = [NSCalendar currentCalendar]; // get current calender
        NSDateComponents* dateOnlyToday = [cal components:( NSYearCalendarUnit |                  NSMonthCalendarUnitNSDayCalendarUnit ) fromDate:today];

    [dateOnlyToday setYear:([dateOnlyToday year] + 1)];

    NSDate *nextYear = [cal dateFromComponents:dateOnlyToday];





2)     NSDate *today1 = [NSDate date];
       NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
       NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
        [offsetComponents setYear:1];
    
        NSDate *nextYear1 = [gregorian dateByAddingComponents:offsetComponents toDate:today1