Tuesday, June 24, 2008

C# : Calculating timing differences

I needed to put some timings in my program. So I need to get a start time, an end time and then calculate the difference between them. TimeSpan to the rescue.



static public DateTime startTime;
static public DateTime endTime;

TimeSpan duration = new TimeSpan();

startTime = DateTime.Now;

...

endTime = DateTime.Now;

duration = endTime - startTime;

"Print" ("Duration is " + duration);



Enjoy!

No comments: