开发者

iPhone time comparison

开发者 https://www.devze.com 2023-01-03 13:51 出处:网络
I am trying to figure out how to create an \'if\' stat开发者_如何转开发ement that uses a time value as a condition.For example:

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

精彩评论

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