我对qt qdatetime比较有困难。
if(now.secsTo(nearest)>0)总是显示相同的号码。
QDateTime now = QDateTime::currentDateTime();
QDateTime nearest = QDateTime::fromString(ui.timetableTable->item(0,2)->data(Qt::DisplayRole).toString(),"dd.MM.yy HH:mm");我怎样才能得到比较两个日期的正确结果。谢谢你帮忙!
发布于 2015-07-24 17:46:28
问题是以不同的格式对对象进行比较。把"dd.MM.yy HH: mm“改为"dd.MM.yyyy HH: mm”,这样你就会感到幸福。事实证明,Qt与1915年和2015年相比。
QDateTime now = QDateTime::currentDateTime();
QDateTime nearest = QDateTime::fromString("26.07.2015 15:35","dd.MM.yyyy HH:mm");
qDebug() << now.toString("dd.MM.yy HH:mm") << nearest.toString("dd.MM.yyyy HH:mm") << now.secsTo(nearest);输出
围绕着你的代码
QDateTime nearest = QDateTime::fromString("26.07.15 15:35","dd.MM.yy HH:mm");
qDebug() << now.toString("dd.MM.yyyy HH:mm") << nearest.toString("dd.MM.yyyy HH:mm") << now.secsTo(nearest);https://stackoverflow.com/questions/31511229
复制相似问题