Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt C++ Convert seconds to formatted string (hh:mm:ss)

Tags:

c++

qt

As I said in title I need to convert seconds to hh:mm:ss

I tried this:

 ui->label->setText(QDateTime::fromTime_t(10).toString("hh:mm:ss"));

But default value for hours is always 01 but I need it to be 00. As result I should get 00:00:10 but I get 01:00:10.

like image 639
Alen Avatar asked May 07 '13 12:05

Alen


2 Answers

Your timezone is included in it thats why. Try this:

QDateTime::fromTime_t(10).toUTC().toString("hh:mm:ss");
like image 91
thuga Avatar answered Sep 21 '22 02:09

thuga


There is no QTime::fromTime_t; possibly you're using QDateTime::fromTime_t, which accounts for time zones and daylight savings.

Instead you can use QTime().addSecs(10).toString(...).

like image 31
ecatmur Avatar answered Sep 20 '22 02:09

ecatmur