The documentation on yyy format says that it's 3 digits or more. So why does the following code throw an exception?
string format = "dd.MM.yyy";
string s = DateTime.Now.ToString(format, CultureInfo.InvariantCulture);
DateTime d = DateTime.ParseExact(s, format, CultureInfo.InvariantCulture); //this throws FormatException
Fiddle
This looks like a bug to me. I tried this to rule out any locale problems and also got the same error:
string format = "dd.MM.yyy";
string s = DateTime.Now.ToString(format, CultureInfo.InvariantCulture);
DateTime d = DateTime.ParseExact(s, format, CultureInfo.InvariantCulture); //this throws FormatException
Edit: Looks to be a duplicate of this question: Why can't DateTime.ParseExact parse DateTime output?
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