0

如果我有一个来自 key 的字符串并且该字符串是一个计时器 (12:00) 如何将 1 分钟添加到计时器,因此标签将显示 12:01:

NSString string = [subDict objectForKey:@"1"];

NSScanner timeScanner=[NSScanner scannerWithString:string];
int hours,minutes;
[timeScanner scanInt:&hours];
[timeScanner scanString:@":" intoString:nil]; 
[timeScanner scanInt:&minutes];

谢谢

4

2 回答 2

0

试试这样

 self.mylabel.text= [NSString stringWithFormat:@"%02d:%02d",[[string substringToIndex:2] intValue],[[string substringFromIndex:3] intValue]+1];
于 2013-07-16T07:32:35.163 回答
0

一定要照顾好携带。至于一个简单的解决方案,您甚至不需要扫描仪:

NSString *timeStr = @"23:59";

NSArray *comps = [timeStr componentsSeparatedByString:@":"];
int h = [comps[0] intValue];
int m = [comps[1] intValue];

h += (m + 1) / 60;
h %= 24;

m = (m + 1) % 60;

NSLog(@"The new time is: %02d:%02d", h, m);
于 2013-07-16T07:41:31.047 回答