开发者

iPhone time comparison

I am trying to figure out how to create an 'if' stat开发者_如何转开发ement that uses a time value as a condition. For example:

if (time <= 10:00) {
    score = 3;
} else if (time <= 20:00) {
    score = 5;
} else {
            score = 9;
}   

I know that a string of "5:23" cannot be compared this way but I don't think I can just turn a string value like that directly into an integer. Any thoughts?


Try this:

NSString *realTimeString = @"10:00";
NSString *someTimeString = [realTimeString stringByReplacingOccurrencesOfString:@":"
                                           withString:@"."];
float time = [someTimeString floatValue];

if (time <= 10.00) {
    score = 3;
} else if (time <= 20.00) {
    score = 5;
} else {
    score = 9;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜