Guest User

Untitled

a guest
Jun 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. NSDateComponents *comps = [[NSDateComponents alloc] init];
  2.  
  3. [comps setDay:day]; // day is 4
  4. [comps setMonth:month]; // month is 4
  5. [comps setYear:2009];
  6.  
  7. /* Make an NSDate out of it */
  8. NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
  9.  
  10. NSDate *date = [gregorian dateFromComponents:comps];
  11. NSLog(@"Date: %@\n",date);
  12.  
  13. /* Calculate the new date */
  14. NSDate *newDate = [date addTimeInterval:60*60*24*offset]; // Offset is 7 here
  15. NSLog(@"New Date: %@\n",newDate);
  16.  
  17. /* Make a NSDateComponent out of the new date */
  18. NSDateComponents *newDateComponents = [gregorian components:(NSDayCalendarUnit | NSWeekdayCalendarUnit) fromDate:newDate];
  19. NSLog(@"New date seperate components --- Day: %d Month:%d\n",[newDateComponents day],[newDateComponents month]);
  20.  
  21.  
  22. 2009-05-22 02:00:43.391 [2317:20b] Date: 2009-04-04 00:00:00 +0300
  23. 2009-05-22 02:00:43.391 [2317:20b] New Date: 2009-04-11 00:00:00 +0300
  24. 2009-05-22 02:00:43.394 [2317:20b] New date seperate components --- Day: 11 Month:2147483647
Add Comment
Please, Sign In to add comment