我有一些以双精度格式存储的秒数(但如果要考虑的话,它们是整数值)。我想将它们转换为hh:mm:ss format
字符串。怎么做?
例如double secs = 120;
会be 00:02:00
.
为什么不能将秒转换为小时、分钟和秒?
double secsDouble = 3666.0; // 1 hour, 1 min, 6 seconds.
int secs = (int)secsDouble;
int h = secs / 3600;
int m = ( secs % 3600 ) / 60;
int s = ( secs % 3600 ) % 60;
QTime t(h, m, s);
qDebug() << time.toString("hh:mm:ss");
QTime time;
time = time.addSecs((int)secs);
qDebug() << time.toString("hh:mm:ss");