Search code examples
c++qtqstringqdatetimeqtime

QTimeDate::currentDateTime not working as expected


i'm trying to use QDateTime for one of my project. But everything is going wrong when i use QDateTime::currentTime().msecsTo() ....

QString FORMAT = "d/MM/yy hh:mm:ss";
QDateTime at = QDateTime::fromString("30/06/15 12:00:00", FORMAT);
qDebug() << QDateTime::currentDateTime().msecsTo(at);  //Current DateTIme : 30/06/15 11:51:00 OUTPUT : -3155755905986

And the out put gives me : -3155755905986 Which doesn't make any sens ...

Any idea ? Thank you.


Solution

  • Actually everything is ok for qt this value is 100 years earlier - 30/06/1915 https://www.unitjuggler.com/convert-time-from-ms-to-yr-365.html?val=3155756569078

    QDate - wrong year

    I suggest using format "dd/MM/yyyy hh:mm:ss"