Home > ASP.NET > Globally overriding default datetime formatting

Globally overriding default datetime formatting

Most people usually do not have access to the server’s locale settings. so if you need to programatically change the global default behaviour of datetime tostring or various locale properties, there is a simple way to do this. 

All you need is to add the following code to global.asax
void Application_BeginRequest(object sender, EventArgs e)
var customCulture = new System.Globalization.CultureInfo(“en-US”);
var DFI = System.Globalization.DateTimeFormatInfo.CurrentInfo.Clone() as System.Globalization.DateTimeFormatInfo;
DFI.DateSeparator = “/”;
DFI.ShortDatePattern = “dd/MM/yyyy”;
DFI.ShortTimePattern = DFI.LongTimePattern = “HH:mm:ss”;
customCulture.DateTimeFormat = DFI;
System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
System.Threading.Thread.CurrentThread.CurrentUICulture = customCulture;

Categories: ASP.NET
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: