C语言程序:计算时间推移后的时间值
#include <stdio.h>
int main() { int h, m, s, n, t;
scanf("%d:%d:%d", &h, &m, &s);
scanf("%d", &n);
t = h * 3600 + m * 60 + s + n; // 将时间转换为秒,并加上n秒
// 对t进行调整
t %= 24 * 3600; // 超过23:59:59就从0点开始计时
h = t / 3600;
m = t % 3600 / 60;
s = t % 60;
printf("%02d:%02d:%02d", h, m, s);
return 0;
}
原文地址: https://www.cveoy.top/t/topic/mGB8 著作权归作者所有。请勿转载和采集!