Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 获取两个NSDate之间的所有日期(不是天)_Objective C_Nsarray_Nsdate - Fatal编程技术网

Objective c 获取两个NSDate之间的所有日期(不是天)

Objective c 获取两个NSDate之间的所有日期(不是天),objective-c,nsarray,nsdate,Objective C,Nsarray,Nsdate,如何获取两次约会之间的所有日期 例如: 开始日期=2011/01/25 结束日期=2011/02/031)查找两个日期之间的天数。那么 for(i=0;i<noofdays;i++) { //Find the next date //add to the array } for(i=0;i1)查找两个日期之间的天数。那么 for(i=0;i<noofdays;i++) { //Find the next date //add to the array } for(i=0;iNSC

如何获取两次约会之间的所有日期

例如: 开始日期=2011/01/25 结束日期=2011/02/03

1)查找两个日期之间的天数。那么

for(i=0;i<noofdays;i++)
{
//Find the next date
//add to the array
}
for(i=0;i1)查找两个日期之间的天数。那么

for(i=0;i<noofdays;i++)
{
//Find the next date
//add to the array
}

for(i=0;i
NSCalendarUnit
用于定义日期之间的步骤,并负责规范化的日期

iOS 8 API,Swift 2.0

    func generateDates(calendarUnit: NSCalendarUnit, startDate: NSDate, endDate: NSDate) -> [NSDate] {

            let calendar = NSCalendar.currentCalendar()
            let normalizedStartDate = calendar.startOfDayForDate(startDate)
            let normalizedEndDate = calendar.startOfDayForDate(endDate)

            var dates = [normalizedStartDate]
            var currentDate = normalizedStartDate

            repeat {

                currentDate = calendar.dateByAddingUnit(calendarUnit, value: 1, toDate: currentDate, options: NSCalendarOptions.MatchNextTime)!
                dates.append(currentDate)

            } while !calendar.isDate(currentDate, inSameDayAsDate: normalizedEndDate)

            return dates
    }

NSCalendarUnit
用于定义日期之间的步骤,并负责规范化日期

iOS 8 API,Swift 2.0

    func generateDates(calendarUnit: NSCalendarUnit, startDate: NSDate, endDate: NSDate) -> [NSDate] {

            let calendar = NSCalendar.currentCalendar()
            let normalizedStartDate = calendar.startOfDayForDate(startDate)
            let normalizedEndDate = calendar.startOfDayForDate(endDate)

            var dates = [normalizedStartDate]
            var currentDate = normalizedStartDate

            repeat {

                currentDate = calendar.dateByAddingUnit(calendarUnit, value: 1, toDate: currentDate, options: NSCalendarOptions.MatchNextTime)!
                dates.append(currentDate)

            } while !calendar.isDate(currentDate, inSameDayAsDate: normalizedEndDate)

            return dates
    }

要查找两个NSDate之间的所有日期,请执行以下操作:

- (void)cerateDaysArray{
    _daysArray = [NSMutableArray new];
    NSCalendar *calendar = [[NSCalendaralloc]initWithCalendarIdentifier:NSGregorianCalendar];
    [calendar setTimeZone:[NSTimeZone systemTimeZone]];
    NSDate *startDate = [_minDate copy];
    NSDateComponents *deltaDays = [NSDateComponents new];
    [deltaDays setDay:1];
    [_daysArray addObject:startDate];
    while ([startDate compare:_maxDate] == NSOrderedAscending) {
       startDate = [calendar dateByAddingComponents:deltaDays toDate:startDate options:0];
       [_daysArray addObject:startDate];
   }
}

要查找两个NSDate之间的所有日期,请执行以下操作:

- (void)cerateDaysArray{
    _daysArray = [NSMutableArray new];
    NSCalendar *calendar = [[NSCalendaralloc]initWithCalendarIdentifier:NSGregorianCalendar];
    [calendar setTimeZone:[NSTimeZone systemTimeZone]];
    NSDate *startDate = [_minDate copy];
    NSDateComponents *deltaDays = [NSDateComponents new];
    [deltaDays setDay:1];
    [_daysArray addObject:startDate];
    while ([startDate compare:_maxDate] == NSOrderedAscending) {
       startDate = [calendar dateByAddingComponents:deltaDays toDate:startDate options:0];
       [_daysArray addObject:startDate];
   }
}

你说的日期而不是天是什么意思?可能是@JoshCaswell的重复。受试者说“不是天”,他想要一个日期列表。@Black Frog:但Inmobile没有费心指出时间间隔。
NSTimeInterval
双精度的,分辨率为毫秒。实际上有数百万个“日期”是的,在“时间与空间”中,每毫秒都是一个不同的日期,但我相信他希望每天都是24小时。你说的日期是什么意思,而不是天?可能是@JoshCaswell的复制品主题说的“不是天”他想要一个日期列表。@Black Frog:但imMobile没有费心指出时间间隔。
NSTimeInterval
是一个
双精度的,分辨率为毫秒。在任意两个时间间隔之间有数百万个“日期”。是的,每毫秒在“时间和空间”中都是不同的日期但我相信他希望每天都是24小时。谢谢。我用objective-c版本来完成我的场景。谢谢。我用objective-c版本来完成我的场景。