开发者

Convert QString Unix epoch time to QString standard time

开发者 https://www.devze.com 2023-02-20 07:25 出处:网络
I need 开发者_StackOverflow中文版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

I need 开发者_StackOverflow中文版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.


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 );
0

精彩评论

暂无评论...
验证码 换一张
取 消