Setting The Time

Started by
5 comments, last by Becko 18 years, 10 months ago
How do you set the date and time of your system clock using C++ to whatever date and time you want, if possible?
Advertisement
You have to use OS-specific calls. You may also need to have the proper privildges (e.g. on windows you need to be an admin to set the clock).
-Mike
How would you do it in Windows?
Quote:Original post by 4
How would you do it in Windows?

::SetSystemTime() or ::SetLocalTime()
Note well that these two functions require special privileges to execute.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Aye, i think MSDN links have it covered in the 'Remarks' for each of both functions...
you can do this in assembler, so your just OS doesnt matter at all (of course you need the privilegs to do this too)

the correct assembler instruction for an x86 : ..... cant remember sorry

(i will search for it in my books a little)

Its Interupt 21h Function 02DH

data looks like this:
AH=02Dh
CH= hours (0-23)
CL= mins (0-59)
DH= secs (0-59)
DL= secs/100 (0-99)

may be useful for some crossplatforming
-------------------------------------------------------------------"Debugging is twice as hard as writing the code in the first place.Therefore, if you write the code as cleverly as possible, you are,by definition, not smart enough to debug it." - Brian W. Kernighan

This topic is closed to new replies.

Advertisement