Open
Description
Type of issue
Missing information
Description
It seems the DateTime.TryParseExact method can throw a System.FormatException
if the format provided is invalid. When tested in ASP.NET MVC 4.7.2, the following code:
DateTime.TryParseExact("01/10/2025", "a", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime parsedDate)
throws a FormatException
with a stack trace:
Input string was not in a correct format
at System.DateTimeFormat.GetRealFormat(String format, DateTimeFormatInfo dtfi)
at System.DateTimeParse.ExpandPredefinedFormat(String format, DateTimeFormatInfo& dtfi, ParsingInfo& parseInfo, DateTimeResult& result)
at System.DateTimeParse.DoStrictParse(String s, String formatParam, DateTimeStyles styles, DateTimeFormatInfo dtfi, DateTimeResult& result)
at System.DateTimeParse.TryParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style, DateTimeResult& result)
at System.DateTimeParse.TryParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style, DateTime& result)
at System.DateTime.TryParseExact(String s, String format, IFormatProvider provider, DateTimeStyles style, DateTime& result)
...
Page URL
Content source URL
https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System/DateTime.xml
Document Version Independent Id
2ba91f2f-bf41-7f7b-b0b3-64c4c0c932d9