When I set the CurrentCulture, how can I override the date format that is set?
Example:
System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
Say I wanted to override the default date format so whenever I output DateTime value it is by default in the format I want.
First of all you need to create an instance of CultureInfo that won't be read only. Then you can create an instance of your DateTimeFormatInfo, configure it appropriately and finally assign it to your CultureInfo object:
var culture = CultureInfo.CreateSpecificCulture("en-US");
//or simply var culture = new CultureInfo("en-US");
var dateformat = new DateTimeFormatInfo();
//then for example:
dateformat.FullDateTimePattern = "dddd, mmmm dd, yyyy h:mm:ss tt";
culture.DateTimeFormat = dateformat;
System.Threading.Thread.CurrentThread.CurrentCulture = culture;
The full specification on how to configure your DateTimeFormatInfo can be found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With