代码如下:
#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();}