我想打印两个给定日期之间的中间日期。
例如fromDate=12/10/2014
和toDate=15/10/2014
然后我想要这个,
12/10/2014
13/10/2014
14/10/2014
15/10/2014.
任何人都可以指导我吗?
答案 0 :(得分:0)
试试这个
//datemin= fromdate , datemax=todate
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
NSDateComponents *days = [[NSDateComponents alloc] init];
NSInteger dayCount = 0;
while ( TRUE ) {
[days setDay: ++dayCount];
NSDate *date = [gregorianCalendar dateByAddingComponents: days toDate: datemin options: 0];
if ( [date compare: dateMax] == NSOrderedDescending )
break;
NSLog(@"%@",date);
// Do something with date like add it to an array, etc.
}