-
Change the clock
Hi, I may have this in wrong place but I thought it dipends on the O/S your using. Ok I have been looking over the net and on here (may have miss something tho) and didnt find a way to do this. I am using windows XP, and using C++ to do this. I want to change the clock time in the lower right hand side on the screen to likes say 1:00 (doesnt matter AM or PM). I dont know how to tho, I know how to check what time it is but not how to change it. Anyone know where I can look or maybe some code I can look at?
-
You can set the clock in C++ to the nearest second using the
the C:
stime()
function in time.h. My documentation tells me it is UNIX only, but I have been using it on Windows with BCB.
In Windows, you could also use the:
SetSystemTime()
Win api call. More accuate than stime().
-
Why do you want to mess around with the system clock?
Backup schedules, browser caches, program make dependencies, email headers, and many other things will be screwed up by bogus clock hacking.
-
To make changing the clock a little easier with how I have my program set up, and mostly b/c I can I guess. What the heck is "bogus clock hacking"?
Ok I tried using SetSystemTime() but no luck atm. I got some code fom MSDN but I have never gotten any luck from their so call "helpful site" LOL.
Code:
#include <windows.h>
// SetNewTime - sets system time
//
// Parameters
// hour - new hour (0-23)
// minutes - new minutes (0-59)
//
// Return value - TRUE if successful, FALSE otherwise
BOOL SetNewTime(WORD hour, WORD minutes)
{
SYSTEMTIME st;
GetSystemTime(&st); // gets current time
st.wHour = hour; // adjusts hours
st.wMinute = minutes; // and minutes
if (!SetSystemTime(&st)) // sets system time
return FALSE;
return TRUE;
}
I know it needs a int main but if I add one it still doesnt work for me. Can someone show me a way on how to us this line of code or maybe tell me what they mass up on so I can fixs it?