zoukankan      html  css  js  c++  java
  • qt DateTime 计算时间

    获取当前时间

    QDateTime t1 = QDateTime::currentDateTime();
    qDebug() << t1.toString("yyyy-MM-dd hh:mm:ss");
    

    string to QDateTime

    QDateTime t1 = QDateTime::fromString("2020-08-03 00:00:00", "yyyy-MM-dd hh:mm:ss");
    qDebug() << t1.toString("yyyy-MM-dd hh:mm:ss");
    

    计算时间差

    QDateTime t1 = QDateTime::fromString("2020-08-03 00:00:00", "yyyy-MM-dd hh:mm:ss");
    qDebug() << t1.toString("yyyy-MM-dd hh:mm:ss");
    
    QDateTime t2 = QDateTime::fromString("2020-08-03 00:00:10", "yyyy-MM-dd hh:mm:ss");
    qDebug() << t2.toString("yyyy-MM-dd hh:mm:ss");
    
    int seconds = t2.toTime_t() - t1.toTime_t();
    qDebug() << "相差:" << seconds << "秒"; // 相差: 10 秒
    qDebug() << "相差:" << seconds * 1000 << "毫秒"; // 相差: 10000 毫秒
    
    int msecs = t2.toMSecsSinceEpoch() - t1.toMSecsSinceEpoch(); // 相差: 10000 毫秒
    qDebug() << "相差:" << msecs << "毫秒";
    
  • 相关阅读:
    信息检索笔记
    北大课程(变态心理学)
    My life
    Excel小技巧(随机点名)
    Flask基础
    CTF
    GDB
    LD_PRELOAD
    AFL-数据变异
    AFL入门
  • 原文地址:https://www.cnblogs.com/ajanuw/p/13608186.html
Copyright © 2011-2022 走看看