Qt计算两个时间字符串的时差

bool LicenseOperation::daysSpacing(QString arg1, QString arg2 ,int days)
{
    QDateTime start,end;
    end = QDateTime::fromString(arg1,"yyyyMMdd");
    start = QDateTime::fromString(arg2,"yyyyMMdd");
    validLicenseDays = start.daysTo(end); //求时间差;
    if(days > validLicenseDays){
        validLicenseDays = days - validLicenseDays;
        return true;
    }else{
        validLicenseDays = 0;
        return false;
    }
}

验证是否在有效时间内。

输入值:20190409,20190408,7

输出结果:true,validLicenseDays = 1

你可能感兴趣的:(Qt,C++)