How to calculate ‘Tomorrow at 4 pm’ in iOS

NSCalendar *calendar = [NSCalendar gregorianCalendar];
NSDateComponents *oneDayComponents = [[NSDateComponents alloc] init];
oneDayComponents.day = 1;
NSDate *tomorrow = [calendar dateByAddingComponents:oneDayComponents toDate:[NSDate date] options:nil];
NSUInteger unitFlags = NSEraCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents *tomorrowAt4PM = [calendar components:unitFlags fromDate:tomorrow];
tomorrowAt4PM.hour = 16;
tomorrowAt4PM.minute = 0;
tomorrowAt4PM.second = 0;
NSDate *alarmDate = [calendar dateFromComponents:tomorrowAt4PM];

http://adcdownload.apple.com//wwdc_2012/wwdc_2012_session_pdfs/session_304__events_and_reminders_in_event_kit.pdf

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s