Skip to content

Instantly share code, notes, and snippets.

@sag333ar
Created November 15, 2013 10:03
Show Gist options
  • Save sag333ar/7482000 to your computer and use it in GitHub Desktop.
Save sag333ar/7482000 to your computer and use it in GitHub Desktop.
add 23:59:59 hours to - (assume today is 30-Jul-2013) example range yesterday = 29-Jul-2013 12:00:00 AM + "to" + 30-Jul-2013 23:59:59 PM
// add 23:59:59 hours to - (assume today is 30-Jul-2013) example range yesterday = 29-Jul-2013 12:00:00 AM + "to" + 30-Jul-2013 23:59:59 PM
- (NSDate*)add24HoursToDate:(NSDate*)date {
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *comp = [cal components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:date];
comp.timeZone=[NSTimeZone defaultTimeZone];
comp.month = comp.month;
comp.year = comp.year;
comp.day = comp.day;
[comp setHour:23];
[comp setMinute:59];
[comp setSecond:59];
NSDate *modifiedDate = [cal dateFromComponents:comp];
return modifiedDate;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment