How to force QDateTime::fromString to read UTC time

c++, qdatetime, qt, utc

Solution

What about setting the time spec after the `fromString` method.

const char* s = "2009-11-05T03:54:00";
d = QDateTime::fromString(s, Qt::ISODate);
d.setTimeSpec(Qt::UTC);
Qt::TimeSpec ts = d.timeSpec();

Problem

I have some input containing UTC time formatted according to iso8601. I try to parse it using QDateTime: ``` const char* s = "2009-11-05T03:54:00"; d.setTimeSpec(Qt::UTC); d = QDateTime::fromString(s, Qt::ISODate); Qt::TimeSpec ts = d.timeSpec(); ``` When this fragment ends, `ts` is set to localTime and `d` contains 3 hours 54 minutes. Does anyone know how to read the date properly?

Original source