Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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".
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
You can’t perform that action at this time.