首页 > 编程知识 正文

qt 获取时间 毫秒,qt获取系统当前毫秒级时间

时间:2023-05-05 05:36:02 阅读:213801 作者:2479

代码如下:

#include <QCoreApplication>#include <QDateTime>#include <QDebug>#include <QTime> int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); //获取时间秒数 qint64 startSec = QDateTime::currentDateTime().toTime_t(); QDateTime current_date_time = QDateTime::currentDateTime(); //获取当前时间 QString current_time = current_date_time.toString("hh:mm:ss.zzz"); qDebug() << current_time; //int QTime::msec () const //Returns the millisecond part (0 to 999) of the time. //获取时间毫秒值 //方法1 QTime t; t.start(); int msec = t.msec(); qDebug() << msec; //方法2 qint64 timestamp = QDateTime::currentDateTime().toMSecsSinceEpoch(); //毫秒级 qDebug() << timestamp; return a.exec();}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。