I am calculating a timecode feature in my programme. For this I need hours, minutes, seconds and an extra value that ticks 24 times per second.
My hours, minutes, seconds are:
public void GetTime()
{
Hours = float.Parse(DateTime.Now.ToString("HH"));
Minutes = float.Parse(DateTime.Now.ToString("mm"));
Seconds = float.Parse(DateTime.Now.ToString("ss"));
Frames = ???
}
How can I calculate the frames value? (without using a timer, if possible)
Thank you.
It sounds like you just want DateTime.Millisecond
and then perform some arithmetic.
However:
DateTime.Now
once, to avoid getting different values from different calls, leading to a very odd displaySomething like:
public void GetTime()
{
var now = DateTime.Now;
Hours = now.Hour;
Minutes = now.Minute;
Seconds = now.Second;
Frames = (now.Millisecond * 24) / 1000;
}
Now that's the computation part. In order to update this regularly, you will need a timer or something similar. Also, due to the nature of system clocks - and timers - you shouldn't expect this code to give you a particularly smooth UI; it may feel a little jerky.
See more on this question at Stackoverflow