I have a Unix timestamp and I need to convert it to human readable date + time. How can it be done in Qt?
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.
QDateTime.setTime_t
You can use the static function: "fromTime_t", like:
qDebug() << QDateTime::fromTime_t(your_time_stamp).toString("dd/MM/yyyy hh:mm:ss");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With