Details
-
Bug
-
Resolution: Won't Do
-
P3: Somewhat important
-
None
-
5.2.1
-
None
-
Windows 8
Description
QDateTime::toString is unable output the local system time in ISODate format with the timezone included.
Using QDateTime::toTimeSpec(Qt::OffsetFromUTC) does not help because it converts the date to UTC using the local timezone offset.
I can get the desired result using a work-around where I retrieve the offset minutes from the local time and then set the offset again, using the same value.
The following SSCCE shows what I mean:
#include <QtCore/QDateTime> #include <QtCore/QDebug> int main(int argc, int argv){ qDebug() << QDateTime::currentDateTime().toString(Qt::ISODate); qDebug() << QDateTime::currentDateTime().toTimeSpec(Qt::OffsetFromUTC).toString(Qt::ISODate); // Work-around that gives the desired results QDateTime now = QDateTime::currentDateTime(); int offset = now.offsetFromUtc(); now.setOffsetFromUtc(offset); qDebug() << now.toString(Qt::ISODate); return 0; }
This generates the following output:
"2014-02-24T10:20:49" "2014-02-24T08:20:49Z" "2014-02-24T10:20:49+02:00"