سؤال

We have some legacy code that can't really be altered which "forces" the user to enter a date in MM/dd/yyyy format through ValidationExpression and a regex on the text field.

However, the C# code will be expecting the date in either MM/dd/yyyy or dd/MM/yyyy depending on the region.

I need to format the entered date into the region specific date.

Any ideas?

So far I've tried DateTime enteredDate = DateTime.ParseExact(StartDateTextBox.Text, "MM/dd/yyyy", CultureInfo.InvariantCulture); but that returns as error stating that "09/04/2013" is not a recognised date.

هل كانت مفيدة؟

المحلول

Replace CultureInfo.InvariantCulture with null.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top