这是愚蠢的,但我必须知道(%)符号的含义,因为我想添加几天。
这是一个例子。
int seconds = 78120;
int forHours = (seconds1 / 3600),
remainder = (seconds1 % 3600),
forMinutes = remainder / 60,
forSeconds = remainder % 60;
NSString *Time = [NSString stringWithFormat:@"%02i:%02i:%02i",forHours,forMinutes,forSeconds];
Label.text = Time;
结果: 21时42分○○秒
我希望结果像( 0天,21:42:00 ),如( DD,HH:mm:ss )
答案 0 :(得分:10)
答案 1 :(得分:3)
%(modulo)给出除法后的余数。
因此,您可以在开始时添加天数的分隔,然后使用modulo获取在几天内删除后的分数:
int seconds = 78120;
int days = seconds / 86400;
// Equivalent to: seconds = seconds - days * 86400 /*# seconds in a day*/;
seconds = seconds % 86400; // seconds remaining less than a day
int forHours = (seconds1 / 3600),
remainder = (seconds1 % 3600), // seconds remaining within an hour
forMinutes = remainder / 60,
forSeconds = remainder % 60; // seconds remaining less than a minute
答案 2 :(得分:2)
模数(%)运算符返回整数除法的余数。
a = 13%5;
这里,a等于3。
尝试:
int fordays = seconds1 / 86400,
remainder = seconds1 % 86400,
forHours = remainder / 3600,
remainder = remainder % 3600,
forMinutes = remainder / 60,
forSeconds = remainder % 60;
1天= 86400秒。