How does _ftime / Windows internal time work?

By : Konrad
Source: Stackoverflow.com
Question!

I have found an interesting issue in windows which allows me to cause the Windows clock (but not the hardware clocks) to run fast - as much as 8 seconds every minute. I am doing some background research to work out how Windows calculates and updates it's internal time (not how it syncs with an NTP servers). Any information anyone has or any documents you can point me to would be greatly appreciated!

Also, if anyone knows how _ftime works please let me know.

By : Konrad


Answers

Regarding how _ftime() works:

If you have Microsoft Visual C++ installed, you probably have the C runtime source installed as well. _ftime() is defined in %ProgramFiles%\Microsoft Visual Studio <version>\VC\crt\src\ftime.c and ftime64.c.

By : bk1e


This MSDN article gives a very brief description of how the system time is handled: "When the system first starts, it sets the system time to a value based on the real-time clock of the computer and then regularly updates the time." Another interesting function is GetSystemTimeAdjustment, which has this to say:

A value of TRUE [for lpTimeAdjustmentDisabled] indicates that periodic time adjustment is disabled. At each clock interrupt, the system merely adds the interval between clock interrupts to the time-of-day clock. The system is free, however, to adjust its time-of-day clock using other techniques. Such other techniques may cause the time-of-day clock to noticeably jump when adjustments are made.

Finally, in regard to _ftime, it appears to be implemented using GetSystemTimeAsFileTime. So it would wrap directly onto the same built-in time facilities as would be used everywhere else.

By : Charlie


This video can help you solving your question :)
By: admin