![]() |
| | #1 |
| Registered User Join Date: Oct 2003
Posts: 104
| Read and set\change system time All I want to be able to do is set the time to something like the year 1999, { MAYBE if it's easy then ... let me enter the date, 12 June, so anything like that and make my time set. |
| Hexxx is offline | |
| | #2 |
| carry on Join Date: Feb 2003 Location: Seattle, WA
Posts: 1,971
| I'm pretty sure the solution depends on what OS you're running. For windows look at the msdn time functions There's even an example of setting the system time.
__________________ "Think not but that I know these things; or think I know them not: not therefore am I short Of knowing what I ought." -John Milton, Paradise Regained (1671) "Work hard and it might happen." -XSquared |
| JaWiB is offline | |
| | #3 | |
| Super Moderator Join Date: Aug 2001
Posts: 7,470
| Time is still supported in MSVC, but I'm not sure about 2005. From MSVC 6 Quote:
__________________ If you aim at everything you will hit something but you won't know what it is. | |
| Bubba is offline | |
| | #4 |
| Registered User Join Date: Aug 2005
Posts: 1,265
| for MS-Windows, use win32 api functions GetSystemTime() and SetSystemTime(). see MSDN for function details. Both use SYSTEMTIME structore, and does NOT use anything in time.h Last edited by Ancient Dragon; 01-01-2006 at 08:28 PM. |
| Ancient Dragon is offline | |
| | #5 |
| Registered User Join Date: Oct 2003
Posts: 104
| ok cool, I belive the msdn fuction should help me on my way... |
| Hexxx is offline | |
| | #6 |
| Super Moderator Join Date: Aug 2001
Posts: 7,470
| And for MFC you can use the CTime class which encapsulates a lot of the nitty gritty stuff and really makes it a lot simpler to work with time and time structures. My point here is that all 3 methods still work as designed. C, Win32, and MFC all work.
__________________ If you aim at everything you will hit something but you won't know what it is. |
| Bubba is offline | |
| | #7 |
| carry on Join Date: Feb 2003 Location: Seattle, WA
Posts: 1,971
| But is it possible to set the system time using only standard functions? Correct me if I'm wrong, but I thought you could only get the time, not change it.
__________________ "Think not but that I know these things; or think I know them not: not therefore am I short Of knowing what I ought." -John Milton, Paradise Regained (1671) "Work hard and it might happen." -XSquared |
| JaWiB is offline | |
| | #8 |
| Super Moderator Join Date: Aug 2001
Posts: 7,470
| I believe you can only get the time, not change it. The reasons are quite obvious. Why would you want to change the date and time of the machine you are working on? The time is gathered from the BIOS and the only way it gets messed up is if the battery dies or some other malfunction occurs. This is probably why they do not let you set the time. And Windows does NOT alter the time of the BIOS, it simply adjusts for the locale settings of the user (BIOS +/- adjust_hours) so even it does not change the time. Last function that actually changed the time I believe was in DOS using time and date at the command prompt. I don't remember if those changed the actual BIOS time however. You can do this programatically through interrupts and by interfering with a certain interrupt which I'll not name here, but why do this when you can just go into the CMOS and alter the BIOS time? Also if you go changing the time in Windows it is possible that it will flag the year as a leap year and/or reset or unset daylight savings time. Of course this will change the minute you alter it to the current date and time. I just fail to see any use for code that does this.
__________________ If you aim at everything you will hit something but you won't know what it is. Last edited by Bubba; 01-02-2006 at 01:26 AM. |
| Bubba is offline | |
| | #9 | |
| Registered User Join Date: Aug 2005
Posts: 1,265
| Quote:
| |
| Ancient Dragon is offline | |
| | #10 |
| Cat without Hat Join Date: Apr 2003
Posts: 8,439
| Bubba, how about an NTP client? Anyway, on Unix, changing the system time requires root privileges. Off the top of my head, the CRT seems to contain nothing that would require root privileges by default on some system.
__________________ All the buzzt! CornedBee"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code." - Flon's Law |
| CornedBee is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|