Last active
August 29, 2015 14:11
-
-
Save sangram-chavan/5097ae61e936f41a3b41 to your computer and use it in GitHub Desktop.
Revisions
-
sangram-chavan renamed this gist
Dec 15, 2014 . 1 changed file with 18 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,21 @@ /* 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 = { -
sangram-chavan created this gist
Dec 15, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ 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); } } }