Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi Friends,

I have stuck at one point. I get milliseconds by using GetTickCount() function. Now I want to convert it in date-time format like HH:MM:SS format.

Is MFC provide api to convert this directly, or I will use any other way? Please suggest me the solution.

C++
DWORD dwTickCount = GetTickCount();
DWORD m_dwNextCommandTickCount = (DWORD)(dwDiff * 1000/dFrameRate + dwTickCount);


In above code I want to convert both dwTickCount and m_dwNextCommandTickCount in time format.

Thanks in advance
Posted

1 solution

The value is in milliseconds so ...

C++
DWORD ticks = GetTickCount();
DWORD milliseconds = ticks % 1000;
ticks /= 1000;
DWORD seconds = ticks % 60;
ticks /= 60;
DWORD minutes = ticks % 60;
ticks /= 60;
DWORD hours = ticks; // may exceed 24 hours.
printf("%d:%02d:%02d.%03d\n", hours, minutes, seconds, milliseconds);


If you don't care about milliseconds, MFC's CTimeSpan class may work for you.

CTimeSpan span(ticks/1000);
printf("%d %02d:%02d:%02d\n", span.GetDays(), span.GetHours(), span.GetMinutes(), span.GetSeconds());
 
Share this answer
 
v2
Comments
Vaibhav_J_Jaiswal 21-Mar-14 6:20am    
Thanks for your help. I got the solution of my problem
manashree sattigeri 10-Feb-23 2:07am    
How-to-convert-the-output-of-GetTickCount-into-time with python

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900