Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert QString Unix epoch time to QString standard time

I need an elegant C++ function that takes a QString parameter containing the unix time (e.g. 1295874681) and converts it into standard time format (e.g Mon, 24 Jan 2011 13:11:21 GMT) containing QString and returns it.

like image 630
yolo Avatar asked Jan 20 '23 03:01

yolo


1 Answers

bool ok;
const uint s = unixTimeStr.toUInt( &ok );
if ( !ok ) {
   ..handle conversion error (unixTimeStr not containing a number)
}
const QDateTime dt = QDateTime::fromTime_t( s );
const QString textdate = dt.toString( Qt::TextDate );
like image 184
Frank Osterfeld Avatar answered Jan 30 '23 23:01

Frank Osterfeld