Wednesday, May 20, 2009

Universal Date Format For windows application in c#.NET

Date Format plays a major role in windows application development in c#.
Because by default, Its set to our Regional Settings's Date Format (Control Panel).If you change Regional Settings's Date Format then your windows application's Format will automatically gets changed.

If you design an application for single System means There is no problem.But If it's Multi User(LAN) & accessed from different system means problem will occur.because each system may have different date formats.

and By Default It set to US format mm/dd/yyyy.But in INDIA we need date in dd/mm/yyyy.so we have to change culture information of our application.Like Below

System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-FR");

Here,
FR refers FRANCE.
for INDIA we can set it as hi-IN(hindi),ta-IN(tamil) for each language.

Just add This Line in Main Form Loading Event.Then in entire Application All Date Conversion methods will have format as dd/mm/yyyy only.

If you want to set different culture info means you can add this line where you need to set a culture at run time.

And also if you retrieve date from a File or some where else as String then after that if you convert it into Date means,It will converted into dd/mm/yyyy format Only.

So we can set DATE FORMAT for entire windows application with the help of above culture settings.

Thank you.

No comments:

Post a Comment