正如上面所说......我不需要秒,因为它不会不断更新。我已经在这个网站和谷歌上搜索了几个小时,但找不到与我需要的完全一样的东西。这是我的代码:
//Sets the percentage calculation
double percent = level / 100;
//Calculates the time left while using the following
double a = 40 * percent;
double b = 400 * percent;
double c = 7 * percent;
double d = 6 * percent;
aTime.text = [NSString stringWithFormat:@"%f", a];
bTime.text = [NSString stringWithFormat:@"%f", b];
cTime.text = [NSString stringWithFormat:@"%f", c];
dTime.text = [NSString stringWithFormat:@"%f", d];
经过计算,比如说,7 小时的 50%,它目前给出了 3.5 小时。我想让它说 3:30。
如您所见,计算是静态的减去水平计算,我只需要知道如何将小数转换为 hh:mm(对于 400 小时来说,甚至可能是几天)。
注意:以上所有数字(40、400、7、6)均以小时为单位。