PDA

View Full Version : How to convert unix time to QDateTime



lni
13th November 2007, 23:26
Hi,

I have a unix time 1194278852, which is 11/05/2007 4:07pm GMT.

How do I use Qt to convert it?

Thanks

jpn
13th November 2007, 23:29
Take a look at QDateTime (especially notice a static member it has).

lni
13th November 2007, 23:54
Hi,

I have a unix time 1194278852, which is 11/05/2007 4:07pm GMT.

How do I use Qt to convert it?

Thanks

I did, I use QDateTime::fromTime_t and it is wrong. The other two does not even come close...

wysota
14th November 2007, 01:25
Hmm... sounds fine to me:

#include <QtCore>
#include <QtDebug>

int main(){
uint x = 1194278852;
qDebug() << QDateTime::fromTime_t(x);
return 0;
}


$ ./x
QDateTime("pon. lis 5 17:07:32 2007")

The answer is in localtime which is GMT+1.