Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-37030

QDateTime::toString does not output timezone for Qt::ISODate format

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • P3: Somewhat important
    • None
    • 5.2.1
    • Core: Date/Time
    • 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"
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Eddy Edward Welbourne
            robbiee Robert Escott
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes