I have a number of seconds stored in a double format (but they are integer values if that's to be concerned). I would like to convert them to a hh:mm:ss format string. How to do that?
hh:mm:ss format
For example double secs = 120; would be 00:02:00.
double secs = 120;
be 00:02:00
You can create a QTime object by using its default constructor and then add your seconds to it:
QTime
double secs = 120; QTime a(0,0,0); a = a.addSecs(int(secs));
QTime time; time = time.addSecs((int)secs); qDebug() << time.toString("hh:mm:ss");
Why can't you convert seconds into hours, mins and seconds?
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");
You can create a
QTime
object by using its default constructor and then add your seconds to it: