Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string ToFormattedString(this TimeSpan value)
- {
- var list = new List<string>(3);
- int days = value.Days;
- int hours = value.Hours;
- int minutes = value.Minutes;
- int seconds = value.Seconds;
- int milliseconds = value.Milliseconds;
- if (days > 1)
- list.Add(String.Format("{0} days", days));
- else if (days == 1)
- list.Add(String.Format("{0} day", days));
- if (hours > 1)
- list.Add(String.Format("{0} hours", hours));
- else if (hours == 1)
- list.Add(String.Format("{0} hour", hours));
- if (minutes > 1)
- list.Add(String.Format("{0} minutes", minutes));
- else if (minutes == 1)
- list.Add(String.Format("{0} minute", minutes));
- if (seconds > 1)
- list.Add(String.Format("{0} seconds", seconds));
- else if (seconds == 1)
- list.Add(String.Format("{0} second", seconds));
- if (milliseconds > 1)
- list.Add(String.Format("{0} ms", milliseconds));
- else if (milliseconds == 1)
- list.Add(String.Format("{0} ms", milliseconds));
- return String.Join(", ", list.ToArray());
- }
Advertisement
Add Comment
Please, Sign In to add comment