The string was not recognized as a valid DateTime. using ParseExact on Windows Server 2012

I'm trying to parse a string to a date using the culture information "en-CA". It works fine on Windows Server 2008 R2, but shows an exception in Windows Server 2012: - The string was not recognized as a valid DateTime.

Below is the code segment: -

 DateTime tvDefaultDate = DateTime.ParseExact("31/12/9999", "dd/MM/yyyy", 
                                                      new CultureInfo("en-CA"));
+1
source share
2 answers

/here it simply represents a "date separator" ( DateTimeFormatInfo.DateSeparator), similar to how a ,thousand separator (not a comma) is displayed with numbers , but .represents a "decimal separator" (not a period).

en-CA -; 31-12-9999. /, , :

DateTime tvDefaultDate = DateTime.ParseExact("31/12/9999", @"dd\/MM\/yyyy",
        new CultureInfo("en-CA"));

; / .

+1

IFormatProvider, null.

DateTime tvDefaultDate = DateTime.ParseExact("31/12/9999", "dd/MM/yyyy", CultureInfo.InvariantCulture);
Console.WriteLine(tvDefaultDate);

:

12/31/9999 12:00:00 AM

( .)

0

All Articles