2

hi i have used NSDateComponents but could not calculate the 5th date

NSDate *now = [NSDate date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

NSDateComponents *dateComponents = [calendar components:NSWeekdayCalendarUnit | NSHourCalendarUnit fromDate:now];
NSInteger weekday = [dateComponents weekday];
NSLog(@"Week %ld",(long)weekday);
Desdenova
  • 5,326
  • 8
  • 37
  • 45
jitendra
  • 41
  • 1

1 Answers1

1

you can use NSDateComponent like this to get next date after some interval

NSDateComponents *dateComponents = [NSDateComponents new];
dateComponents.minute = 15; //to get time after 15 minutes
dateComponents.day = 5; //to get date after 5 days
//and similarly you can calculate date or time after hour, minute, seconds day, week, etc
NSDate *date = [[NSCalendar currentCalendar] dateByAddingComponents:dateComponents toDate:[formatterWithAM dateFromString:startTime.text] options:0]
Amit Singh
  • 2,698
  • 21
  • 49