System time in floating point seconds since midnight (VB and C#)

829b65f69fe30269207b8000bc88f959
0
Dawoodoz 101 Apr 02, 2013 at 19:26 c#

I have trouble with finding the floating point system time from midnight in C#.
I need it for animation and therefor it would be useless to have it rounded to whole seconds and restarting every minute like in a calendar time.
The timer object can’t be used because it only wait at least the specified delay and drift away if the system is busy.
In VB6 you write Timer to get it.
In VB.net you write VB.Timer() after importing Microsoft.VisualBasic to VB.
How do I get the same thing in C# so that my SDK samples can be consistent between multiple languages?

4 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Apr 02, 2013 at 20:34

If you just need a high-resolution timer, you can use the Stopwatch class. If you really want the amount of time since midnight (or some other specific time) then you’ll probably need to use DateTime.Ticks and convert to floating point yourself.

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Apr 03, 2013 at 01:09

Wouldn’t it be better to use the QueryPerformanceFrequency (if on Windows) which has a precision of the system GHZ clock (3GHZ PC will give have a 3 billion ticks per second precision)?

A638aa42130293f319eda7fa4ba121f4
0
fireside 141 Apr 03, 2013 at 01:36

If you are in the .Net framework, there is very little difference between languages since they compile to the same thing. Just google c# timer, or .Net timer.

829b65f69fe30269207b8000bc88f959
0
Dawoodoz 101 Apr 03, 2013 at 07:43

@Reedbeta

If you just need a high-resolution timer, you can use the Stopwatch class. If you really want the amount of time since midnight (or some other specific time) then you’ll probably need to use DateTime.Ticks and convert to floating point yourself.

TotalSeconds from stopwatch worked well. :)