2

我有一些以双精度格式存储的秒数(但如果要考虑的话,它们是整数值)。我想将它们转换为hh:mm:ss format字符串。怎么做?

例如double secs = 120;be 00:02:00.

4

3 回答 3

9

您可以QTime使用其默认构造函数创建一个对象,然后将您的秒数添加到它:

double secs = 120;

QTime a(0,0,0);
a = a.addSecs(int(secs));
于 2015-06-15T07:58:13.333 回答
1

为什么不能将秒转换为小时、分钟和秒?

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");
于 2015-06-15T08:00:57.793 回答
0
QTime time;
time = time.addSecs((int)secs);
qDebug() << time.toString("hh:mm:ss");
于 2015-06-15T07:58:55.403 回答