Created
September 18, 2016 03:38
-
-
Save WenchaoD/4ee6276e36b2a5ccd02fddd367ebaae2 to your computer and use it in GitHub Desktop.
Get dates between two days
This file contains hidden or 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 *fromDate = ...; | |
NSDate *toDate = ...; | |
NSCalendar *gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian]; | |
NSInteger daysDiff = [gregorian components:NSCalendarUnitDay fromDate:fromDate toDate:toDate options:0].day; | |
NSMutableArray<NSDate *> *array = [NSMutableArray arrayWithObject:fromDate]; | |
for (int i = 1; i <= daysDiff; i++) { | |
NSDate *date = [gregorian dateByAddingUnit:NSCalendarUnitDay value:daysDiff toDate:toDate options:0]; | |
if (date) [array addObject:date]; | |
} | |
NSArray<NSDate *> *dates = array.copy; | |
// Do something with dates |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment