Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Time Span Calculation
QtWS25 Last Chance

Time Span Calculation

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 3.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Khalifa
    wrote on last edited by
    #1

    Hi there ...
    Greating for you all
    How can I Calculate the time span between two times

    1 Reply Last reply
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by Paul Colby
      #2

      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.

      K 1 Reply Last reply
      3
      • Paul ColbyP Paul Colby

        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.

        K Offline
        K Offline
        Khalifa
        wrote on last edited by
        #3

        @Paul-Colby
        Thank You very much

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          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

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          2
          • P Offline
            P Offline
            Plastic.Jesus
            wrote on last edited by Plastic.Jesus
            #5

            I have a pretty complete timespan implementation here:
            https://github.com/StevePunak/KanoopCommonQt/blob/master/include/Kanoop/timespan.h

            There'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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved