Preferred way to handle UTC / local time in Qt QDateTime?

I have a code in which I write a QDateTime to a file ...

someQDateTime.toUTC().toString(Qt::ISODate)

and when I read it with help QDateTime::fromString(), I get a time that is interpreted as being in the system time zone. I can manually add “Z” to the line when I write it out, or use it setTimeSpec()after I read it, and then everything will be fine, but is this the preferred way? Should notString () know to write Z when timeSpec is UTC?

+3
source share
2 answers

, , ISO 8601 ( 4.2.4, pdf ), a Z UTC . , QDateTime::toString() , QDateTime::fromString() . ISO 8601 4.3.2 ( [T] - , Z):

" [T] , , ".

(https://bugreports.qt.io/), Qt , .

+3

Qt 9698 QDateTime::toString(Qt::ISODate). . .

0

Source: https://habr.com/ru/post/1756856/


All Articles