QTimeDate::currentDateTime未按预期工作

QTimeDate::currentDateTime not working as expected

本文关键字:工作 currentDateTime QTimeDate      更新时间:2023-10-16

我正试图将QDateTime用于我的一个项目。但是当我使用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

结果显示:-315755905986这没有任何意义。。。

知道吗?非常感谢。

实际上qt一切正常,这个值早于100年-1915年6月30日https://www.unitjuggler.com/convert-time-from-ms-to-yr-365.html?val=3155756569078

Q日期-错误年份

我建议使用格式"dd/MM/yyyy hh:MM:ss"

Qt文档显示if the other datetime is earlier than this datetime, the value returned is negative。我认为这是意料之中的行为。