Parse a single number using the "c" standard format string.
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
string intervalString, format;
TimeSpan interval;
CultureInfo culture;
intervalString = "12";
format = "c";
try {
interval = TimeSpan.ParseExact(intervalString, format, null);
Console.WriteLine("'{0}' --> {1}", intervalString, interval);
}
catch (FormatException) {
Console.WriteLine("'{0}': Bad Format for '{1}'", intervalString, format);
}
catch (OverflowException) {
Console.WriteLine("'{0}': Overflow", intervalString);
}
}
}
Related examples in the same category