Takes total elapsed milliseconds and returns a string description of the elapsed time, such as "593 milliseconds, or 4.203 seconds, or 5.111 minutes".
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; | |
namespace com.williambryanmiller.time { | |
class TimeFormatting { | |
public static string getDurationDesc(double numMilliseconds) { | |
const double Minute = 60000; | |
const double Second = 1000; | |
double duration = 0; | |
string result = string.Empty; | |
if (numMilliseconds >= Minute) { | |
duration = numMilliseconds / Minute; | |
//result = String.Format("{0:0.00}", duration) + " minutes"; | |
result = duration.ToString("N3") + " minutes"; | |
} else { | |
if (numMilliseconds >= Second) { | |
duration = numMilliseconds / Second; | |
//result = String.Format("{0:00}", duration) + " seconds"; | |
result = duration.ToString("N3") + " seconds"; | |
} else { | |
result = numMilliseconds.ToString() + " milliseconds"; | |
} | |
} | |
return result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment