50
1
using System; using System.Collections.Generic; using System.Text;
2
using System.Diagnostics;
3
4
public static class Program
5
{
6
/// <summary>
7
/// Human readable TimeStamp using modern Action delegate, leaving out zero parts and variable length placeholder formating
8
/// </summary>
9
/// <param name="milliseconds">a long type</param>
10
/// <returns>Human readable timespan string</returns>
11
public static string HumanReadableTimeSpan(this long milliseconds)
12
{
13
if (milliseconds == 0) return "0 ms";
14
15
StringBuilder sb = new StringBuilder();
16
17
Action<int, StringBuilder, int> addActionToSB = //or pass an entire new format!
18
(val, displayunit, zeroplaces) =>
19
{if (val > 0)
20
sb.AppendFormat(
21
" {0:DZ}X".Replace("X", displayunit.ToString())
22
.Replace("Z",zeroplaces.ToString())
23
,val
24
);
Cached Result