Created
May 20, 2013 04:40
-
-
Save iandundas/5610459 to your computer and use it in GitHub Desktop.
NSDateComponents example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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