QTimeDate::currentDateTime not working as expected

917 Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

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"

0
On

Qt doc says if the other datetime is earlier than this datetime, the value returned is negative. I think it is expected behaviour.