Link to home
Start Free TrialLog in
Avatar of chanmo
chanmo

asked on

SYSTEMTIME arithmetic

I want to obtain the time difference between 2 SYSTEMTIME variables. I'm recommended to convert them to ULARGE_INTEGER before doing subtraction. But I don't know how to do ULARGE_INTEGER arithmetics. Please suggest some ways to get the SYSTEMTIME difference. I would also like to know how can I add 5 minutes to a SYSTEMTIME variable containing the current time. Thank you.
Avatar of chanmo
chanmo

ASKER

Adjusted points from 7 to 22
chanmo,
a easier structure for your purpose is FILETIME.
You can convert a SYSTEMTIME-object into FILETIME with
SystemTimeToFileTime()

then cast it to LARGE_INTEGER and do your operations.
See SDK doc of FILETIME for further information
Avatar of chanmo

ASKER

I know I can convert SYSTEMTIME to FILETIME. My problem is I don't know how to do ULARGE_INTEGER (or LARGE_INTEGER) arithmetic operations. Is it that I should cast the member of LARGE_INTEGER to __int64 and then use the operators? When I did this to calculate the difference between 2 SYSTEMTIME differed by 5 seconds, the result was 1601/1/1 00:00:05. So I want to know whether there is a better way to obtain "5 seconds" as result. I also want to know what I should do if I want to add 5 minutes to a SYSTEMTIME returned by GetLocalTime().
If you are using MFC, try to use CTime class, it's quite convenient.
ASKER CERTIFIED SOLUTION
Avatar of JMu
JMu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chanmo

ASKER

Thank you very much for your help!