TimeSpan timeSpan = new TimeSpan(5, 4, 3, 2);
string str = timeSpan.ToString(@"d\d\:h\h\:m\m\:s\s", System.Globalization.CultureInfo.InvariantCulture);
See Custom TimeSpan format strings for how to format TimeSpans.
Although note that the negative TimeSpancannot be distinguished from the positive. They look as if they were canceled . For this, it -new TimeSpan(5,4,3,2)will be displayed as 5d:4h:3m:2s. If you want to display negative numbers, you must format your own numbers, but properties TimeSpan.
source
share