Time Span Calculation
-
wrote on 8 May 2016, 09:08 last edited by
Hi there ...
Greating for you all
How can I Calculate the time span between two times -
wrote on 8 May 2016, 09:30 last edited by Paul Colby 5 Aug 2016, 09:30
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.
wrote on 8 May 2016, 09:52 last edited by@Paul-Colby
Thank You very much -
Someone started working on a
QTimeSpanclass long ago, but it hasn't made it into the official code base yet: https://forum.qt.io/topic/3160/qtimespan-interest -
wrote on 7 Jul 2024, 17:46 last edited by Plastic.Jesus 7 Jul 2024, 17:49
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