Skip to content

Instantly share code, notes, and snippets.

@iandundas
Created May 20, 2013 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iandundas/5610459 to your computer and use it in GitHub Desktop.
Save iandundas/5610459 to your computer and use it in GitHub Desktop.
NSDateComponents example
NSDate *today = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
[gregorian setLocale:[NSLocale currentLocale]];
NSDateComponents *nowComponents = [gregorian components:NSYearCalendarUnit | NSWeekCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:today];
[nowComponents setWeekday:2]; //Monday
[nowComponents setHour:0]; //1 a.m.
[nowComponents setMinute:0];
[nowComponents setSecond:0];
return [gregorian dateFromComponents:nowComponents];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment