我希望当你乘以时,小数超过60,它会在正常数字上再增加一个(很难解释,但像时钟一样:7:59,8:00得到它?
答案 0 :(得分:2)
你想做这样的事情......然后这就是答案
NSInteger seconds = totalSecondsSinceStart % 60;
NSInteger minutes = (totalSecondsSinceStart / 60) % 60;
NSInteger hours = totalSecondsSinceStart / (60 * 60);
NSString *result = [NSString stringWithFormat:@"%02ld:%02ld:%02ld", hours, minutes, seconds]
编辑:
每当你想将agian舍入为0,并将+1添加到前一个计数器时使用:%来查找余数。和/找到商。两者结合将为您提供理想的结果。
e.g。 NUM = 95;
sec=num%60; //remainder 35 is stored in sec.
min=num/60; //evaluates to 1.somthing, but due to integer devision, quotient 1 is stored in min.