Hi,
I finished developing the .net windows application.problem is in date format.the application developed with the date format of "MM/dd/yyyy" with this appication working fine.but now i want to change the dateformat to "dd/MM/yyyy" by setting this format im getting the folling error "String was not regcognized as valid date format". i have to change the format in one place so that it gets effect in all over the application.
i have tried withe the below code.but its not working.
CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
culture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
culture.DateTimeFormat.LongTimePattern = "";
System.Threading.Thread.CurrentThread.CurrentCulture = culture;
Regards
Kanna
Loading
Kannabiran BPosted May 19, 2010, 7:17 AM
Jaish MathewsPosted May 19, 2010, 6:14 AM
It's working. You may missed the correct conversion. Just check below boldded lines. You need to convert Date to the the specified format you set using ToShortDateString, ToLongDateString etc...
CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
culture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
culture.DateTimeFormat.LongTimePattern = "";
System.Threading.Thread.CurrentThread.CurrentCulture = culture;
MessageBox.Show(DateTime.Now.ToShortDateString());
culture.DateTimeFormat.ShortDatePattern = "MM/dd/yyyy";
MessageBox.Show(DateTime.Now.ToShortDateString());
culture.DateTimeFormat.LongDatePattern = "MMM/dddd/yyyy";
MessageBox.Show(DateTime.Now.ToLongDateString());