1

I have unixtimestamp 1579106713 which represent 1/15/2020 16:45:13 and I need to convert this time in Qt, I have used the code but getting different value

 int unixTimeTmp = 1579106713; // 1/15/2020 16:45:13
 QDateTime timestampq;
 timestampq.setTime_t(unixTimeTmp);
 qDebug() << timestampq.toString();

Give the output

Wed Jan 15 11:45:13 2020 // expect Wed Jan 15 16:15:33 2020

When I checked here https://www.epochconverter.com, I have seen that I have to get the GMT output, but no idea how I can get using Qt

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
CodeDezk
  • 1,230
  • 1
  • 12
  • 40

1 Answers1

2

You need to set the timespec to Qt::UTC. Like this:

int unixTimeTmp = 1579106713; // 1/15/2020 16:45:13
QDateTime timestampq;
timestampq.setTime_t(unixTimeTmp);
timestampq.setTimeSpec(Qt::UTC);
qDebug() << timestampq.toString();
Toby Speight
  • 27,591
  • 48
  • 66
  • 103
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97