QDateTime转换

QDateTime dateTime;
QString strDateTime = dateTime.currentDateTime().toString("yyyy-MM-dd hh:mm:ss");

// 从字符串转换为毫秒(需完整的年月日时分秒)
datetime.fromString("2018-07-18 12:10:10:111", "yyyy-MM-dd- 
 hh:mm:ss.zzz").toMSecsSinceEpoch();

// 从字符串转换为秒(需完整的年月日时分秒)
datetime.fromString("2018-07-18 12:10:10:111", "yyyy-MM-dd hh:mm:ss.zzz").toTime_t();

// 从毫秒转换到年月日时分秒
datetime.fromMSecsSinceEpoch(1315193829218).toString("yyyy-MM-dd hh:mm:ss.zzz");

// 从秒转换到年月日时分秒(若有zzz,则为000)
datetime.fromTime_t(1315193829).toString("yyyy-MM-dd hh:mm:ss[:zzz]");




QTime startTime = QTime::currentTime();
QTime stopTime  = QTime::currentTime();
求两个时间毫秒差
qint64 temp = startTime.msecsTo(stopTime);

 

你可能感兴趣的:(qt)