我对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-20 07:04:41
QDateTime::fromString()时,默认值分配给没有在格式字符串中提供的任何字段。默认值提供这里。"yy"作为一年格式传递时,该年的默认值为1900 + "yy"字段中传递的值。示例:
QDateTime最近= QDateTime::fromString("02.07.15 12:15","dd.MM.yy HH:mm");qDebug()<<最近;//将给予: QDateTime("1915-07-02 12:15:15:00.000“)QDateTime::addYears()修改默认值。对于上面的例子:
最近= nearest.addYears(100);https://stackoverflow.com/questions/31499638
复制相似问题