Last active
December 26, 2015 22:09
-
-
Save justinmfischer/d003fbf5a1031b3098cc to your computer and use it in GitHub Desktop.
Round Date To 5 Minutes
This file contains 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 *) 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