Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NSDateComponents *comps = [[NSDateComponents alloc] init];
- [comps setDay:day]; // day is 4
- [comps setMonth:month]; // month is 4
- [comps setYear:2009];
- /* Make an NSDate out of it */
- NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
- NSDate *date = [gregorian dateFromComponents:comps];
- NSLog(@"Date: %@\n",date);
- /* Calculate the new date */
- NSDate *newDate = [date addTimeInterval:60*60*24*offset]; // Offset is 7 here
- NSLog(@"New Date: %@\n",newDate);
- /* Make a NSDateComponent out of the new date */
- NSDateComponents *newDateComponents = [gregorian components:(NSDayCalendarUnit | NSWeekdayCalendarUnit) fromDate:newDate];
- NSLog(@"New date seperate components --- Day: %d Month:%d\n",[newDateComponents day],[newDateComponents month]);
- 2009-05-22 02:00:43.391 [2317:20b] Date: 2009-04-04 00:00:00 +0300
- 2009-05-22 02:00:43.391 [2317:20b] New Date: 2009-04-11 00:00:00 +0300
- 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