Many of the times, developers code their application and forget that different systems can have different date and time format settings. This causes the application to crash. This article helps you in setting the Custom global culture info environment specific to your application.
I was working on an existing application and found out the carelessness of the developers. If I changed my system settings, I could not run this application - this issue was assigned to me for fixing. So I did in this way.
Using the Code
The code is self explanatory. Now developers need not worry about the environment settings for the time and date formats.
Set and initialize all the Culture Settings at the start of your application:
static void Main()
System.Globalization.CultureInfo cultureInfo =
System.Globalization.DateTimeFormatInfo dateTimeInfo =
dateTimeInfo.DateSeparator = "/";
dateTimeInfo.LongDatePattern = "dd-MMM-yyyy";
dateTimeInfo.ShortDatePattern = "dd-MMM-yy";
dateTimeInfo.LongTimePattern = "hh:mm:ss tt";
dateTimeInfo.ShortTimePattern = "hh:mm tt";
cultureInfo.DateTimeFormat = dateTimeInfo;
Application.CurrentCulture = cultureInfo;
Thread.CurrentThread.CurrentCulture = cultureInfo;
Thread.CurrentThread.CurrentUICulture = cultureInfo;
Points of Interest
Well most of you have tried the same thing but maybe it doesn't allow you to change the
DateFormats directly. I tried to change the
CurrentCulture.DateFormatInfo at various times, but... :)
- 26th July, 2007: Initial post