Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. time difference

time difference

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
6 Posts 5 Posters 1 Views 1 Watching
  • 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.
  • M Offline
    M Offline
    marcoslav
    wrote on last edited by
    #1

    How to get time difference in seconds. CTime t1; t1.GetCurrentTime(); after some time say after 3 seconds CTime t2; t2.GetCurrentTime(); Now I want difference between t2 and t1 in seconds that is 3 seconds; Marcoslav

    N V D 3 Replies Last reply
    0
    • M marcoslav

      How to get time difference in seconds. CTime t1; t1.GetCurrentTime(); after some time say after 3 seconds CTime t2; t2.GetCurrentTime(); Now I want difference between t2 and t1 in seconds that is 3 seconds; Marcoslav

      N Offline
      N Offline
      NiceNaidu fo
      wrote on last edited by
      #2

      Instead of all the above use DWORD dwStartTime = GetTickCount(); //Some Code DWORD dwStopTime = GetTickCount(); Now the Difference ( dwStopTime - dwStartTime ) gives u the required difference in Seconds Appu.. "If you judge people, you have no time to love them."

      N 1 Reply Last reply
      0
      • N NiceNaidu fo

        Instead of all the above use DWORD dwStartTime = GetTickCount(); //Some Code DWORD dwStopTime = GetTickCount(); Now the Difference ( dwStopTime - dwStartTime ) gives u the required difference in Seconds Appu.. "If you judge people, you have no time to love them."

        N Offline
        N Offline
        Naveen
        wrote on last edited by
        #3

        NiceNaiduNow the Difference ( dwStopTime - dwStartTime ) gives u the required difference in Seconds

        I think this will return the difference in milli seconds.. nave

        N 1 Reply Last reply
        0
        • M marcoslav

          How to get time difference in seconds. CTime t1; t1.GetCurrentTime(); after some time say after 3 seconds CTime t2; t2.GetCurrentTime(); Now I want difference between t2 and t1 in seconds that is 3 seconds; Marcoslav

          V Offline
          V Offline
          Viorel
          wrote on last edited by
          #4

          In MFC, use subtract operator and CTimeSpan class:

          CTime time1 = CTime::GetCurrentTime();
          ::Sleep(3000);
          CTime time2 = CTime::GetCurrentTime();
          CTimeSpan diff = time2 - time1;
          LONG seconds = diff.GetTotalSeconds();
          

          Note the usage of CTime::GetCurrentTime static function.

          1 Reply Last reply
          0
          • N Naveen

            NiceNaiduNow the Difference ( dwStopTime - dwStartTime ) gives u the required difference in Seconds

            I think this will return the difference in milli seconds.. nave

            N Offline
            N Offline
            NiceNaidu fo
            wrote on last edited by
            #5

            Yes .u r right. U will get the time difference in milli seconds. Divide the difference with 1000 to get Seconds. Thanks for the correction Naveen. Appu.. "If you judge people, you have no time to love them."

            1 Reply Last reply
            0
            • M marcoslav

              How to get time difference in seconds. CTime t1; t1.GetCurrentTime(); after some time say after 3 seconds CTime t2; t2.GetCurrentTime(); Now I want difference between t2 and t1 in seconds that is 3 seconds; Marcoslav

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              marcoslav wrote:

              t1.GetCurrentTime();

              Wrong. Use this instead:

              t1 = CTime::GetCurrentTime();


              "The largest fire starts but with the smallest spark." - David Crow

              "Judge not by the eye but by the heart." - Native American Proverb

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups