Last active
December 10, 2015 22:59
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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