QT 计算两个日期时间差

1、计算两个日期天数差


    QDateTime time1 = QDateTime::fromString("2020-11-26 16:40:02", "yyyy-MM-dd hh:mm:ss");

    //QDateTime time2 = QDateTime::fromString("2020-11-26 16:43:02", "yyyy-MM-dd    hh:mm:ss");
     
    QDateTime time2 = QDateTime::currentDateTime();
    
    int days = time1.dayTo(tim2);

    qDebug() << "time2 - time1=" << days ;

2、计算两个日期分钟差

   QDateTime time1 = QDateTime::fromString("2020-11-26 16:40:02", "yyyy-MM-dd hh:mm:ss");

   QDateTime time2 = QDateTime::fromString("2020-11-26 16:43:02", "yyyy-MM-dd    hh:mm:ss");
    
    int minutes = time1.secsTo(tim2);

    qDebug() << "time2 - time1=" << days ;

猜你喜欢

转载自blog.csdn.net/my_angle2016/article/details/110224758