Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QML DateTimeAxis show UTC time



  • Dear all,

    I have noticed that 'min' and 'max' properties of DateTimeAxis, are displayed based on the locale settings, meaning the time shown in the time axis is in the current locale. Is it possible to show the datetime on Axis, in UTC?

    Follows an example according to my use case.

    This is the QML part where the DateTimeAxis is defined. 'min' property is attached to the 'metisChart.minTime' which is member of a custom cpp class.

    DateTimeAxis {
      id: axisX
      min: metisChart.minTime
      max: metisChart.maxTime
      gridVisible: true
      format: metisChart.xAxisLabel ? metisChart.xAxisLabel : "hh:mm"
      titleText: "Timestamp"
      tickCount: 6
    
      onMinChanged: {
        console.log("QML min: " + axisX.min.toUTCString())
      }
    }
    

    QML output using .toUTCString():

    QML min: Thu Dec 30 12:53:41 2021 GMT
    

    This is the CPP part where the new datetime value is set and the corresponding signal is emitted. Using qInfo() the time is printed to show that it is correctly displayed in UTC.

    void ChartLiveData::setMinTime(QDateTime time)
    {
      if(m_minTime == time)
        return;
    
      m_minTime = time;
      qInfo() << "CPP minTime " << m_minTime.toUTC();
      emit minTimeChanged(m_minTime);
    }
    

    CPP output:

    CPP minTime  QDateTime(2021-12-30 12:53:41.289 UTC Qt::UTC)
    

    As shown in the image bellow, the time axis is showing the datetime shifted by +2 hours (min is 14:53), which is expected according to my TimeZone.
    DateTime_issue.png

    Is there a way to set the Axis display format in UTC? I haven't found any useful information on the documentation. The only thing that is mentioned is to format based on a specific locale, which sounds like a very bad practice in my case.

    Thank you in advance.

    Kind regards


Log in to reply