How to translate milliseconds into normal time for understanding

I write a small player using QMediaPlayer. There is a signal that is triggered every 1000 milliseconds.

I'm wondering, is it possible to somehow convert milliseconds to normal time like 2:23 (2 minutes twenty-three seconds), or do I need to make 2 widgets; one for minutes and the second for seconds?

Author: Alexander Chernin, 2020-07-31

1 answers

Use the QTime class and, for example, the QTime::addMSecs(int ms)

QTime time(0, 0);

time = time.addMSecs(1000);
qDebug() << time; // Вывод в формате hh:mm:ss.zzz QTime("00:00:01.000")

time = time.addMSecs(1000);
qDebug() << time; // QTime("00:00:02.000")

time = time.addSecs(650); // + 650 секунд
qDebug() << time; // QTime("00:10:52.000")

...

If you need it in your own format, then use the method QTime::toString(const QString& format)

qDebug() << time.toString("mm.ss"); // 00.02
qDebug() << time.toString("mm:ss"); // 00:02
 5
Author: Alexander Chernin, 2020-08-01 08:28:13