Main Site Documentation

Setting the clock


I’m trying to set the clock & later on see the time…but all i ever get is zero minutes & seconds
If I convert the whole system time to a string it gives ""
what’s missing?

           DateTime normal = new DateTime(2012, 4, 19, 11, 5, 32);

later on in the program:

                SystemTime see_the_time=new SystemTime();
               Debug.Print("its now " + see_the_time.Minute.ToString() + ":" + see_the_time.Second.ToString());


What you’re missing is that you never actually read anything into the time variable. You need to use the GetMachineTime() call.


Thanks…is there more than one SystemTime? On the other hand it does appear as a variable, but I’d think it would just be auto set to the present (system) time

sure seems like there are a lot of times:

reatltime clock
how are these related, if at all?

I finally used DateTime.Now which seems to work with the initialization posted
[italic]DateTime.Now: Gets the system’s current date and time, expressed in local time[/italic]
…but isn’t that system time, as I had originally posted…guess not!


The SystemTime you used is an object type, nothing more. That means all that your code did was create a NEW object, with a type of SystemTime, and then tried to print it’s values. Your assumption that “it should be set to the current time” is wrong. It’s an object, you use it how you want.

How do they relate? They have different contexts and are all different, but are all ways to interact with times. There’s at least two independent timesources in a microprocessor, the system time and the RTC if it has one. The system time runs off the system crystal/oscillator which is typically not overly accurate, and the RTC is independent and has a 32,768hz crystal that makes it easy to keep accurate time (using overflow of a 15-bit register)

Here’s what you should do.

On boot, see if your RTC has a valid time.
If yes, set the system time from that.
From then on, use which always will be the system time.
If you are really concerned about accuracy, periodically (using a timer, say every hour) compare system time and RTC and adjust it if necessary.



Thanks—that’s a wonderful description & very clear. I was getting to these realizations, but bit-by-bit. Having you description of these multiple topics in one place clarifies it. The MSDN/SDK help often reminds me of someone throwing a bunch of jigsaw pieces on the floor.