One part of my program calls a certain method several times.
How can this method track the time between each time it is called?
I thought to use some global variables:
var lastTime = ?;
var currentTime = ?;
var elapsedTime = ?;
public DoSomething()
{
currentTime = TimeRightNowInSeconds;
elapsedTime = currentTime - lastTime;
// do stuff with elapsedTime...
lastTime = TimeRightNowInSeconds;
}
but I have no idea how I measure the time in seconds.
Consider using DateTime and TimeSpan (Be careful to use DateTime.UtcNow to avoid issues with daylight saving boundaries)
e.g.
This can also be done with a Stopwatch (which is more accurate and doesn't suffer from problems with daylight saving boundaries)