-2

如何在 iphone sdk 代码中比较开始日期和结束日期?

示例:->

if ([nowdate compare:raceStartDate] == NSOrderedDescending && [nowdate compare:raceEndDate] == NSOrderedAscending)
{  

}
4

2 回答 2

2
NSDate *date1;
NSDate *date2;


if ([date1 compare:date2] == NSOrderedDescending) {
    NSLog(@"date1 is later than date2");        

} else if ([date1 compare:date2] == NSOrderedAscending) {
    NSLog(@"date1 is earlier than date2");

} else {
    NSLog(@"dates are the same");

}
于 2013-10-29T05:07:56.197 回答
0

尝试这个

- (BOOL)date:(NSDate*)nowdate isBetweenDate:(NSDate*)raceStartDate andDate:(NSDate*)raceEndDate
{
    if ([nowdate compare:raceStartDate] == NSOrderedAscending)
        return NO;

    if ([nowdate compare:raceEndDate] == NSOrderedDescending) 
        return NO;

    return YES;
}
于 2013-10-29T05:28:25.177 回答