1.两个时间戳做减法(差值)
QDateTime time1 = QDateTime::fromString("2019-09-19 18:40:02", "yyyy-MM-dd hh:mm:ss"); QDateTime time2 = QDateTime::fromString("2019-09-19 18:43:02", "yyyy-MM-dd hh:mm:ss"); qDebug() << "time2 - time1=" << time1.secsTo(time2);
输出为 180,单位为秒
2. 时间格式
QDateTime::currentDateTime ().toString ("yyyy_MM_dd hh:mm:ss zzz")