1、计算两个日期天数差
1 QDateTime time1 = QDateTime::fromString("2020-11-26 16:40:02", "yyyy-MM-dd hh:mm:ss");
2 //QDateTime time2 = QDateTime::fromString("2020-11-26 16:43:02", "yyyy-MM-dd hh:mm:ss");
3 QDateTime time2 = QDateTime::currentDateTime();
4 int days = time1.daysTo(tim2);
5 qDebug() << "time2 - time1=" << days ;
2、计算两个日期分钟差
1 QDateTime time1 = QDateTime::fromString("2020-11-26 16:40:02", "yyyy-MM-dd hh:mm:ss");
2 QDateTime time2 = QDateTime::fromString("2020-11-26 16:43:02", "yyyy-MM-dd hh:mm:ss");
3 int minutes = time1.secsTo(tim2);
4 qDebug() << "time2 - time1=" << minutes ;