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

Qt/QML, QDateTime losing an hour when coming into QML

    XMLWordPrintable

Details

    • Linux/X11

    Description

      Refer to my SO question: https://stackoverflow.com/questions/59202237/qt-qml-qdatetime-losing-an-hour-when-coming-into-qml

      #ifndef TESTOBJECT_H
      #define TESTOBJECT_H
      
      #include <QObject>
      #include <QDateTime>
      
      class TestObject : public QObject
      {
          Q_OBJECT
      public:
          TestObject(QObject* parent = nullptr) : QObject(parent) { }
          Q_INVOKABLE QDateTime getDateTime1() {
              return QDateTime(QDate(1945, 9, 28), QTime(11, 0, 0, 0), Qt::TimeSpec::UTC);
          }
          Q_INVOKABLE QDateTime getDateTime2() {
              return QDateTime(QDate(2011, 11, 04), QTime(11, 0, 0, 0), Qt::TimeSpec::UTC);
          }
      };
      
      #endif // TESTOBJECT_H
      

      Then from QML:

      console.log(instance.getDateTime1());
      console.log(instance.getDateTime2());
      

      Here is the output:

      qml: Fri Sep 28 06:00:00 1945 GMT-0400
      qml: Fri Nov 4 07:00:00 2011 GMT-0400
      

      Attachments

        Issue Links

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              pauldotknopf Paul Knopf
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: