Skip to content
April 12, 2010 / kiranpatils

How to use System.Diagnostics.Stopwatch?

Stopwatch is a good guy provided by MS to accurately measure elapsed time.

System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();

// Your Time Consuming Code goes here..


// 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);

Happy Coding! 🙂



Leave a Comment
  1. aspen / Apr 13 2010 2:39 am

    Не получается скормить ваш rss читалке Abilon. Точнее могу, но читать не получается – прога по ходу не может получить новости. Пытаюсь добавить эту ленту – Подскажите придурку – кто чем читает

  2. Juan Pablo / Oct 1 2012 7:01 pm

    With the overload of ToString method in .NET 4, you can parse with ease to mm:ss.fff

    Here is an example


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: