DateTime.TryParsedoes not work on Windows 7 when we change the regional settings to Italian. I even tried TryParseExact, but no luck. Does anyone know about this or have come across this type of script?
The code is something like this:
string[] formats = {"M/d/yyyy h:mm:ss tt", "M/d/yyyy h:mm tt", "MM/dd/yyyy hh:mm:ss", "M/d/yyyy h:mm:ss", "M/d/yyyy hh:mm tt", "M/d/yyyy hh tt", "M/d/yyyy h:mm", "M/d/yyyy h:mm", "MM/dd/yyyy hh:mm", "M/dd/yyyy hh:mm", "dd/MM/yyyy HH:mm"};
if (DateTime.TryParseExact(cb.Text, formats, CultureInfo.InVariantCulture, DateTimeStyles.AllowLeadingWhite, out date_and_time))
but returns false.
or
I even tried:
if (DateTime.TryParse(cb.Text, CultureInfo.InvariantCulture, DateTimeStyles.None,out date_and_time) == true)`
cb.Text is a string that contains a string representation of a DateTime.
Sunil source
share