qt - Converting QString containing PostgreSQL timestamp to QDateTime -
i'm having trouble seemingly simple problem: want qdatetime qstring containing timestamp. got timestamp postgresql, doesn't matter. here code not work:
qstring timestamp = "2010-10-09 19:21:46+02:00"; qstring format = "yyyy-mm-dd hh:mm:sstzd"; qdatetime dt = qdatetime::fromstring(timestamp, format); qdebug() << dt.tostring(); // outputs empty string
there must obvious i'm missing. thanks!
there 2 mistakes making. there no tzd in format specifications, removed time zone information since not need in app doing:
timestamp.chop(6);
and used following format qdatetime. note lowercase format characters:
qdatetime createdat = qdatetime::fromstring(timestamp, "yyyy-mm-dd hh:mm:ss");
thanks above helping out.
Comments
Post a Comment