Advertisement Jump to content


This topic is now archived and is closed to further replies.


How do I make a "timer"(I'm a beginner)

This topic is 6855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do I make a timet that count the amount of milliseconds that have passed since the timer has started. example: timer start do lots of stuff print "how much time has gone"

Share this post

Link to post
Share on other sites
If you''re using Windows, you can call the WIN32 API function GetTickCount() to get the amount of milliseconds from Windows start in the beginning into some variable, do the "stuff", then call it again and substract the old tick count from the new tick count.

Share this post

Link to post
Share on other sites
Windows has a millisecond multimedia timer,
If u include ''winmm.lib'' you have access to the function:-

DWORD timeGetTime();

which reurns the time elapsed since windows was started, and as long as u''r app doesn''t run any longer than 49.71 days constantly then u''ll be fine.(if it does for some reason go over this u would have to use the difference between twot values - but I doubt windows can run for 49 days without crashing)

Now for u''r specific case u simply need to have to variables, and compare the two, i.e:-

double start,end,elapsed;
start = timeGetTime();

//Do other stuff....

end = timeGetTime();
elapsed = end-start;

cout << "time elapsed: " << elapsed;

This could be simplified to elapsed = start-timeGetTime(); and leave out the end variable.
I hope thats helped, if theres any errors feel free to complain

Hey I knew the answer thats a first.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!