I am receiving a FormatError exception from this call to TimeSpan.ParseExact, but the MSDN documentation that I am reading says that this format should be correct:
TimeSpan timeSpan = TimeSpan.ParseExact("172100", "HHmmss", CultureInfo.InvariantCulture);
Can someone please tell me why this is not working? I am doing almost exactly the same thing with a call to DateTime.ParseExact and this works fine:
DateTime datetTime = DateTime.ParseExact("090820", "yyMMdd", CultureInfo.InvariantCulture);
TimeSpan does not use the same formatting rules as DateTime.
You want hhmmss, not HHmmss.
You're looking at the wrong page in MSDN - you want something like:
http://msdn.microsoft.com/en-us/library/se73z7b9.aspx
With ref to this more accurate documentation: http://msdn.microsoft.com/en-us/library/ee372287.aspx
You need to use hh
for hours, not HH
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With