一杯清酒邀明月
天下本无事,庸人扰之而烦耳。
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 ;

 

posted on 2023-09-07 16:24  一杯清酒邀明月  阅读(1235)  评论(0编辑  收藏  举报