开发者

objective-c method to check if date is between to others

i have two NSDates and i want to check if a third one is between those others. But now, even if i know that the date i want to check is between the others, it says its not. Maybe one of you can help me.So the 开发者_StackOverflow社区if-clause is always TRUE.

Thanks a lot!!

current = [ar objectAtIndex:j];
            gameDate = [current gameDate];
            gameDate = [gameDate substringToIndex:[gameDate length] - 9]; 
            GameDay = [df dateFromString:gameDate];

            if(![GameDay compare:start] == NSOrderedAscending && ![GameDay compare:end] == NSOrderedDescending){
                [DateArray addObject:[ar objectAtIndex:j]];
            }


You can try simply using the NSDate NSTimeInterval (which is really just a typeDef for double) and comparing like this:

if ([myCheckDate timeIntervalSince1970] < [mybetweenDate1 timeIntervalSince1970] && [myCheckDate timeIntervalSince1970] > [mybetweenDate2 timeIntervalSince1970])

Hope that helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜