Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.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
Ios 两个日期之间的日期_Ios_Nsdate - Fatal编程技术网

Ios 两个日期之间的日期

Ios 两个日期之间的日期,ios,nsdate,Ios,Nsdate,这是检查serverOnNowDate是否介于publishedStartTime和publishedEndTime之间的好方法吗 return !( [self.publishedStartTime compare:serverOnNowDate] == NSOrderedDescending || [self.publishedEndTime compare:serverOnNowDate] == NSOrderedAscending ); 您可以使用下面的方法 - (B

这是检查serverOnNowDate是否介于publishedStartTime和publishedEndTime之间的好方法吗

 return !( [self.publishedStartTime compare:serverOnNowDate] == NSOrderedDescending
        || [self.publishedEndTime compare:serverOnNowDate] == NSOrderedAscending );

您可以使用下面的方法

- (BOOL)inputDate:(NSDate*)date start:(NSDate*)beginDate end:(NSDate*)endDate
{
    if ([date compare:beginDate] == NSOrderedAscending)
        return NO;

    if ([date compare:endDate] == NSOrderedDescending) 
        return NO;

    return YES;
}

作为实例方法编写:

- (BOOL)isBetweenDate:(NSDate *)earlierDate andDate:(NSDate *)laterDate
{
    // first check that we are later than the earlierDate.
    if ([self compare:earlierDate] == NSOrderedDescending) {

        // next check that we are earlier than the laterData
        if ( [self compare:laterDate] == NSOrderedAscending ) {
            return YES;
        }
    }

    // otherwise we are not
    return NO;
}
用法:

NSDate *date = [NSDate now];

if ( [date isBetween:startDate andDate:finishDate] ) {
    NSLog(@"Between dates!!!");
}

如果正好介于两者之间,那么您面临的问题是什么。您的代码运行良好这用于检查1000个对象的数组中是否有开始/结束日期包括serverTime的对象。。。找不到任何对象,但我确信其中一些对象在此方法中应该返回YES。此方法的可能副本应该是类方法,或者您不需要3个参数,因为您可以使用self。较短的形式:
return[self-compare:earlierDate]==sensorderedescing&[self-compare:laterDate]==sensorderedescing