Thursday, July 10, 2008

Fix Dateformat independent of culture

In a project we had a requirement of using the same date format for all cultures. This can be easily centralised in InitializeCulture() event using DateTimeFormat property of CultureInfo. We did it in a base class which is being inherited by all web pages.

CultureInfo cInf = new CultureInfo(cultureName);
cInf.DateTimeFormat.ShortDatePattern ="dd/MM/yyyy";
cInf.DateTimeFormat.DateSeparator = "/";
System.Threading.Thread.CurrentThread.CurrentCulture = cInf;

No comments: