C # DateTime.ParseExact fractional seconds issue

I have a script where I read values ​​from a file and convert it to DateTime . The problem is that at one time sometimes I have 5 decimal places in seconds, and sometimes at 6. For example, 19:23:30.12345 and 12:13:33.123456 . If I need to analyze this, I cannot use ss.fffff or ss.ffffff . What should I do?

+4
source share
2 answers

Try using six capital F. According to the documentation in the Title section of the F-format specifier :

The number of F format specifiers used with ParseExact, TryParseExact, ParseExact, or the TryParseExact method indicates the maximum number of most significant digits of a second fraction that may be present for successful string analysis.

+5
source

Why is something special necessary? Does DateTime.Parse (stringFromFile) work directly, without a specifier?

0
source

Source: https://habr.com/ru/post/1334158/


All Articles