Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TimeSpan.ParseExact() returns false for apparently valid format

Tags:

c#

timespan

Why does this code return false? This question/answer strongly implies that it should return true.

TimeSpan.TryParseExact("04:00:01", "hh:mm:ss", CultureInfo.CurrentCulture, out x);

Using InvariantCulture also returns false and TimeSpan.ParseExact() throws an invalid format exception. HH:mm:ss is wrong, as per the above question.

How is 04:00:01 breaking the format for hh:mm:ss?

like image 524
Devin Burke Avatar asked Dec 17 '12 19:12

Devin Burke


1 Answers

Use @"hh\:mm\:ss" for your format.

like image 121
Mir Avatar answered Oct 01 '22 18:10

Mir