PDA

View Full Version : Converting QString to QDateTime with format



dantom
9th August 2018, 15:37
Hello,

i am trying to convert a simple QString to a QDateTime using some format. The conversion doesn't work -> The QDateTime object "dt" is not valid. What is wrong?
I am using Qt 5.

QString strValue = "2018-08-09T12:38:57.709000Z";
QString format = "yyyy-MM-ddTHH:mm:ss.zzzzzzZ";
QDateTime dt = QDateTime::fromString (strValue, format);

d_stranz
9th August 2018, 16:51
Looks like too many digits in the milliseconds field. QDateTime::fromString() seems to imply only "z" or "zzz" (3 digits max) are allowed in this field, because the range is given as 000 - 999. What would "709000" in the ms field mean, anyway? 709 seconds? Or 709.000 ms? The parser doesn't know.