I have some code where I write a QDateTime to a file…
someQDateTime.toUTC().toString(Qt::ISODate)
and when I read it back using QDateTime::fromString(), I get the time interpreted as being in the system’s time zone. I can manually append “Z” to the string when I write it out, or use setTimeSpec() after I read it, and then everything is fine, but is this the preferred way of doing this? Shouldn’t toString() know to write out a Z when the timeSpec is UTC?
Well, at least according to ISO 8601 (section 4.2.4, pdf here), a
Zis needed to differentiate between UTC and local time. Seems as ifQDateTime::toString()doesn’t follow this advice, whileQDateTime::fromString()knows about it. ISO 8601 also contains this note in section 4.3.2 (where [T] is the time zone indicator, i.e. Z):“By mutual agreement of the partners in information interchange, the character [T] may be omitted in
applications where there is no risk of confusing a date and time of day representation with others defined in this
International Standard.”
You could always file a bug report (https://bugreports.qt.io/) to tell the Qt people about this small inconsistency and see what they have to say about it.