问题
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