QDateTime dateTime;
QString dateTime_str = dateTime.currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
// 从字符串转换为毫秒(需完整的年月日时分秒)
datetime.fromString("2011-09-10 12:07:50:541", "yyyy-MM-dd hh:mm:ss:zzz").toMSecsSinceEpoch();
// 从字符串转换为秒(需完整的年月日时分秒)
datetime.fromString("2011-09-10 12:07:50:541", "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]");
- 获取系统时间
#include
...
QDateTime sysDateTime;
qDebug() <
#include
qint64 startTime = QDateTime::currentMSecsSinceEpoch();
qDebug() << startTime;
while (1)
{
if (QDateTime::currentMSecsSinceEpoch() - startTime > interval) // interval为需要延时的时间(ms)
{
break;
}
}
QTime endTime = QTime::currentTime();
qDebug() << startTime.msecsTo(endTime); // 结果为ms