setDateTimeFormat adds an hour

淺唱寂寞╮ 提交于 2019-12-11 23:20:26

问题


I would like to display my x axis in the hh:mm:ss format. It basicaly works, but there is one problem. The displayed time doesnt start from 00:00:00 but from 01:00:00. I thought maybe its because the time is in ap mode, but I havent specified that, here is how I do it:

customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
customPlot->xAxis->setDateTimeFormat("hh:mm:ss");

And the plot at point 0 starts from hour 1:

I would appreciate all help regarding this. How to make the starting point 0 shown as 00:00:00?


回答1:


Use HH (or H to avoid the leading zero). Lowercase h is for AM/PM hour format, which starts to count from 1.

Font: http://doc.qt.io/qt-5/qdatetime.html#toString

If the problem still persists, it should be timezone related. Add

customPlot->xAxis->setDateTimeSpec(Qt::UTC)

before SetTimeFormat



来源:https://stackoverflow.com/questions/31093640/setdatetimeformat-adds-an-hour

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!