QDateTime convertion fromString is invalid (guess because of time zone)
Unsolved
General and Desktop
-
I have a date time format like this
"2020-04-26T11:16:59+01:00"
I tried this code and also different formatst, i always get an invalid QDateTime.
QString datetime("2020-04-26T11:16:59+01:00"); QString formatst("yyyy-MM-ddTHH:mm:ss±tzoff"); //QString formatst("yyyy-MM-ddTHH:mm:ss±HH:mm"); //QString formatst("yyyy-MM-ddTHH:mm:ssZHH:mm"); QDateTime dt; dt.fromString(datetime, formatst); qDebug() << Q_FUNC_INFO << datetime << dt;
Can someone help to find convert the date/time from string?
-
- That's a
Qt::ISODate
format, you can usefromString(datetime, Qt::ISODate)
QDateTime::fromString()
is a static method, it won't do any change to yourdt
object.
So the correct way is
QDateTime dt = QDateTime::fromString(datetime, Qt::ISODate);
- That's a