秒转为时、分、秒格式
int time_sec = 11320;
QString time = QTime(0, 0, 0).addSecs(static_cast<int>(time_sec)).toString(QString::fromLatin1("HH:mm:ss"));
qDebug() << time; // 输出:"03:08:40"
毫秒转为时、分、秒、毫秒格式
int time_ms = 211320;
QString time = QTime(0, 0, 0, 0).addMSecs(static_cast<int>(time_ms)).toString(QString::fromLatin1("HH:mm:ss:mm"));
qDebug() << time;
毫秒单转为时、分、秒、毫秒格式
int time_ms = 1234;
QString timer = QTime(0, 0, 0,0).addMSecs(static_cast<int>(time_ms)).toString(QString::fromLatin1("HH:mm:ss:zzz"));
qDebug() << timer;
将字符串时、分、秒转为秒
QString time_str = "01:20:30"; //时分秒
QTime time = QTime::fromString(time_str);
qDebug() <<"时:"<< time.hour();
qDebug() <<"分:"<< time.minute();
qDebug() <<"秒:"<< time.second();
qDebug() <<"总秒数:"<< time.hour() * 60 * 60 + time.minute() * 60 + time.second();
/*
时: 1
分: 20
秒: 30
总秒数: 4830
*/
将字符串时、分、秒、毫秒转为毫秒
QString time_str = "01:20:30.300"; //时分秒毫秒
QTime time = QTime::fromString(time_str);
qDebug() <<"时:" << time.hour();
qDebug() <<"分:" << time.minute();
qDebug() <<"秒:" << time.second();
qDebug() <<"毫秒:" << time.msec();
qDebug()<<"总毫秒数:" << time.hour() * 60 * 60 * 1000 + time.minute() * 60 * 1000 + time.second() * 1000 + time.msec();
/*
时: 1
分: 20
秒: 30
毫秒: 300
总毫秒数: 4830300
*/
标签:mm,QTime,毫秒,QString,time,互转,qDebug,序列化
From: https://www.cnblogs.com/DarkH/p/18244667