Default date format throughout the project – 1


You don’t need to do any subclassing and its not possible to override DateTime (because its a struct, not a class). The formatting is determine by the System.Globalization.CultureInfo object on the page. If you have a specific culture you want, you can declare it in the <%@ Page culture=”here” %> or in web.config’s . http://samples.basicdatepicker.com/cultureinfo.aspx In your case, you have described a format that isn’t coming from a culture. So you change it programmatically on each page request. It can be done on individual pages in Page_Load or globally in the Application_BeginRequest method. System.Globalization.CultureInfo vNewCulture = (CultureInfo) System.Threading.Thread.CurrentThread.CurrentCulture.Clone(); vNewCulture.DateTimeFormat.ShortDatePattern = “dd-MMM-yyyy”; vNewCulture.DateTimeFormat.DateSeparator = “-“; vNewCulture.DateTimeFormat.ShortTimePattern = “hh:mm”; // add “tt” if you need AM/PM descriptors vNewCulture.DateTimeFormat.LongTimePattern = “hh:mm:ss” System.Threading.Thread.CurrentThread.CurrentCulture = vNewCulture;

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s