/* Custom TimeSpan formar @"%s", @"%s\.f", @"%s\.f", @"%s\.ff", @"%s\.fff", @"%m\:%s", @"%m\:%s\.f", @"%m\:%s\.ff", @"%m\:%s\.fff", @"%h\:%m\:%s", @"%h\:%m\:%s\.f", @"%h\:%m\:%s\.ff", @"%h\:%m\:%s\.fff" */ void Main() { string[] inputs = { @"14:15:16.520", @"14:15:16.52", @"14:15:16.5", @"14:15:16", @"15:16.520", @"15:16.52", @"15:16.5", @"15:16", @"16.520", @"16.52", @"16.5", @"0.5", @"16", }; string[] formats = { @"%s", @"%s\.f", @"%s\.f", @"%s\.ff", @"%s\.fff", @"%m\:%s", @"%m\:%s\.f", @"%m\:%s\.ff", @"%m\:%s\.fff", @"%h\:%m\:%s", @"%h\:%m\:%s\.f", @"%h\:%m\:%s\.ff", @"%h\:%m\:%s\.fff", }; TimeSpan interval; // Parse each string in inputs using formats and the de-DE culture. foreach (string input in inputs) { try { if (TimeSpan.TryParseExact(input, formats, null, out interval)) Console.WriteLine("{0} --> {1}", input, interval.ToString("g")); else Console.WriteLine("Unable to parse '{0}'", input); } catch (FormatException) { Console.WriteLine("{0} --> Bad Format", input); } catch (OverflowException) { Console.WriteLine("{0} --> Overflow", input); } } }