Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert from timestamp to date in Qt?

I have a Unix timestamp and I need to convert it to human readable date + time. How can it be done in Qt?

like image 283
user63898 Avatar asked May 29 '10 12:05

user63898


3 Answers

int unixTime = 1234567890;
QDateTime timestamp;
timestamp.setTime_t(unixTime);
qDebug() << timestamp.toString(Qt::SystemLocaleShortDate);

That should get you going. Like Matthew said, see QDateTime.setTime_t, as well as QDateTime.toString. The toString has an enumeration with several different options, as well as an overload where you can pass a string allowing however much customization you like.

like image 98
Jake Petroules Avatar answered Nov 13 '22 09:11

Jake Petroules


QDateTime.setTime_t

like image 36
Matthew Flaschen Avatar answered Nov 13 '22 10:11

Matthew Flaschen


You can use the static function: "fromTime_t", like:

qDebug() << QDateTime::fromTime_t(your_time_stamp).toString("dd/MM/yyyy hh:mm:ss");

like image 5
Tarek.Mh Avatar answered Nov 13 '22 08:11

Tarek.Mh