Skip to content

Instantly share code, notes, and snippets.

@diederikh
Created July 26, 2012 11:20
Show Gist options
  • Save diederikh/3181541 to your computer and use it in GitHub Desktop.
Save diederikh/3181541 to your computer and use it in GitHub Desktop.
31th Jan + 1 Month
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *comp = [NSDateComponents new];
comp.day = 31;
comp.month = 1;
comp.year = 2012;
NSDateComponents *addMonthComp = [NSDateComponents new];
addMonthComp.month = 1;
NSLog(@"31th Jan + 1 month: %@",[cal dateByAddingComponents:addMonthComp toDate:[cal dateFromComponents:comp] options:0]);
@diederikh
Copy link
Author

output:

2012-07-26 13:19:48.320 Untitled[81574:707] 31th Jan + 1 month: 2012-02-28 23:00:00 +0000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment