C# timer, how to add duration to a page

56 comments

here is some page / function timer code:


		Stopwatch stopWatch = new Stopwatch();
		stopWatch.Start();


		GetInfo(); //

		stopWatch.Stop();
		// Get the elapsed time as a TimeSpan value.
		TimeSpan ts = stopWatch.Elapsed;
		// Format and display the TimeSpan value. 
		string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
			ts.Hours, ts.Minutes, ts.Seconds,
			ts.Milliseconds / 10);
		Console.WriteLine("RunTime " + elapsedTime);
		ResultHelp.Text += "<br>Run Time (h:mm:ss.ms) " + elapsedTime;
		

Comments

very helpful comment
Posted by Jeremy Nicholls | jeremy@beweb.co.nz

Mike very helpfully pointed out that you can also do this: Var start = new Datetime() ... Stuff .... <%=start.fmtmillisecondselapsed()%> if fmtmillisecondselapsed is available.



Leave a Comment