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

QTimeZone(Qt::UTC) returns incorrect UTC offset (+1 second)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: P2: Important P2: Important
    • None
    • 6.7.3, 6.8.3, 6.9.1, 6.10.0
    • Core: Date/Time
    • None
    • Linux/Wayland

      Summary

      Using QTimeZone(Qt::UTC) results in an invalid offset of +1 second, causing incorrect QDateTime values when used in time zone conversions.

      Reproduction Code

      auto dateTime = QDateTime::currentDateTime();
      auto actualDateTime1 = dateTime;
      actualDateTime1.setTimeZone(QTimeZone(Qt::UTC));
      qDebug() << "Actual DateTime 1:" << actualDateTime1;
      auto actualDateTime2 = dateTime;
      actualDateTime2.setTimeZone(QTimeZone("UTC"));
      qDebug() << "Actual DateTime 2:" << actualDateTime2;
      

      Observed Output

      Actual DateTime 1: QDateTime(2025-08-04 00:13:36.973 UTC+00:00:01 Qt::TimeZone UTC+00:00:01)
      Actual DateTime 2: QDateTime(2025-08-04 00:13:36.973 UTC Qt::TimeZone UTC)
      

      Expected Output

      Both conversions should produce the same result — with UTC+00:00:00.

      Workaround

      Use QTimeZone("UTC") instead of QTimeZone(Qt::UTC).

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

            Eddy Edward Welbourne
            vmudryk Volodymyr Mudryk
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes