Skip to content

Instantly share code, notes, and snippets.

@sag333ar
Created November 15, 2013 10:04
Show Gist options
  • Save sag333ar/7482009 to your computer and use it in GitHub Desktop.
Save sag333ar/7482009 to your computer and use it in GitHub Desktop.
Current date - 24 hours = Today 5 PM - 24 hours = Yesterdays 5 PM
- (NSDate*)remove24HoursToDate:(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:0];
[comp setMinute:0];
[comp setSecond:0];
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