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 << "毫秒";
    
  • 相关阅读:
    scrollTop
    ……
    放下
    值得纪念的一天
    php新手上路(六)
    image map
    文字多出用点代替
    js formatter
    感谢,今天刚申请了博客园,
    接口的作用
  • 原文地址:https://www.cnblogs.com/ajanuw/p/13608186.html
Copyright © 2011-2022 走看看