Time Span Calculation
-
Hi @Khalifa,
How can I Calculate the time span between two times
If you mean between two QDateTimes, you can use QDateTime::daysTo, QDateTime::secsTo, or QDateTime::msecsTo, like:
QDateTime then = QDateTime::currentDateTime(); QThread::msleep(100); QDateTime now = QDateTime::currentDateTime(); qDebug() << then.msecsTo(now);
Or if you mean between to points in time, you can use QElapsedTimer, like:
QElapsedTimer timer; timer.start(); QThread::msleep(100); qDebug() << timer.elapsed();
Cheers.
-
Hi @Khalifa,
How can I Calculate the time span between two times
If you mean between two QDateTimes, you can use QDateTime::daysTo, QDateTime::secsTo, or QDateTime::msecsTo, like:
QDateTime then = QDateTime::currentDateTime(); QThread::msleep(100); QDateTime now = QDateTime::currentDateTime(); qDebug() << then.msecsTo(now);
Or if you mean between to points in time, you can use QElapsedTimer, like:
QElapsedTimer timer; timer.start(); QThread::msleep(100); qDebug() << timer.elapsed();
Cheers.
@Paul-Colby
Thank You very much -
Someone started working on a
QTimeSpan
class long ago, but it hasn't made it into the official code base yet: https://forum.qt.io/topic/3160/qtimespan-interest -
I have a pretty complete timespan implementation here:
https://github.com/StevePunak/KanoopCommonQt/blob/master/include/Kanoop/timespan.hThere's a bunch of other goodies in this library as well. Here's a link to the whole enchilada:
https://github.com/StevePunak/KanoopCommonQt.git