Skip to content

Instantly share code, notes, and snippets.

@justinmfischer
Last active December 26, 2015 22:09
Show Gist options
  • Save justinmfischer/d003fbf5a1031b3098cc to your computer and use it in GitHub Desktop.
Save justinmfischer/d003fbf5a1031b3098cc to your computer and use it in GitHub Desktop.
Round Date To 5 Minutes
+ (NSDate *) roundDateTo5Minutes:(NSDate *) mydate {
NSDateComponents *time = [[NSCalendar currentCalendar] components:NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:mydate];
NSInteger minutes = [time minute];
int remain = minutes % 5;
if (remain < 3){
mydate = [mydate dateByAddingTimeInterval:-60 * (remain)];
}else{
mydate = [mydate dateByAddingTimeInterval:60 * (5-remain)];
}
return mydate;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment