Page 1 of 1

DateTime Parse and TryParse Issues - CultureInfo

Posted: Thu Feb 18, 2016 7:57 am
by cz_1
Hi,

It seems that browsers have a problem with the CultureInfo class when parsing DateTimes. Tested on IE and Chrome (Error messages are from Chrome):

Code: Select all

DateTime dt;
dt = DateTime.Parse(dtStr, CultureInfo.InvariantCulture);

--> TypeError: Cannot read property 'MemberwiseClone' of undefined

Code: Select all

DateTime.TryParse(dtStr, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt);

--> Error: Memoized value is undefined.

No exception is thrown if using CultureInfo at the ToString() method, but the returned string-value is "undefined":

Code: Select all

var dtToString = dt.ToString(CultureInfo.InvariantCulture);

--> results in a string "undefined"

These bugs are not that critical but annoying - because in the debugger, all is working fine.. and for multi-language support, using the CultureInfo class would be nice..

Best Regards,
Christoph

Re: DateTime Parse and TryParse Issues - CultureInfo

Posted: Mon Feb 22, 2016 5:30 am
by JS-Support @Userware
Thanks. We have indeed reported issues related to the CultureInfo class. We plan a complete rewrite of the DateTime class in Mid-2016. Let us keep in touch. Thanks again.

Re: DateTime Parse and TryParse Issues - CultureInfo

Posted: Tue Dec 13, 2016 11:13 pm
by clintwelbar
public static bool TryParse(
string s,
out DateTime result
)

This method is similar to the DateTime.Parse(String) method, except that the TryParse(String, DateTime) method does not throw an exception if the conversion fails. Also, this method tries to ignore unrecognized data, if possible, and fills in missing month, day, and year information with the current date. The TryParse method is culture dependent so be very careful if you decide use it. More about...date conversion

Clint