Skip to content

Instantly share code, notes, and snippets.

@randyburden
Last active December 10, 2015 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randyburden/4506233 to your computer and use it in GitHub Desktop.
Save randyburden/4506233 to your computer and use it in GitHub Desktop.
Simple StopWatcher helper class to give you back a nicely formatted elapsed time.
using System;
using System.Diagnostics;
namespace PDFMerger.Helpers
{
public static class StopwatchHelper
{
/// <summary>
/// Returns the elapsed time of the stopwatch in a formatted string.
/// </summary>
/// <returns>A string with a customized output of the elapsed time</returns>
public static string GetElapsedTime( Stopwatch stopWatch )
{
TimeSpan ts = stopWatch.Elapsed;
string elapsedTime;
if ( ts.Minutes > 0 )
elapsedTime = String.Format( "{0:00} min. {1:00}.{2:00} sec.", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 );
else if ( ts.Seconds > 0 )
elapsedTime = String.Format( "{0:00}.{1:00} sec.", ts.Seconds, ts.Milliseconds / 10 );
else
elapsedTime = string.Format( "{0} ms.", ts.Milliseconds );
return elapsedTime;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment