Converts TimeSpan to string with ToString() using the specified format: "c", "g", "G"
using System;
public class Class1
{
public static void Main()
{
TimeSpan[] spans = { TimeSpan.Zero, new TimeSpan(-14, 0, 0, 0, 0),
new TimeSpan(1, 2, 3),
new TimeSpan(0, 0, 0, 0, 250),
new TimeSpan(99, 23, 59, 59, 999),
new TimeSpan(3, 0, 0),
new TimeSpan(0, 0, 0, 0, 25) };
string[] fmts = { "c", "g", "G" };
foreach (TimeSpan span in spans)
{
foreach (string fmt in fmts)
Console.WriteLine("{0}: {1}", fmt, span.ToString(fmt));
Console.WriteLine();
}
}
}
Related examples in the same category