In our web.config I am using the following tag to determine the interface language of an ASP.NET website.
<globalization enableClientBasedCulture="true" culture="auto:en-GB" uiCulture="auto:en"/>
This works as expected: Client wo request a specific localisation get it, everybody else is happily looking at the en-GB settings.
Due to company policy I need to change the date format to the ISO 8601 standard format (YYYY-MM-DD) for everybody. Is this possible at a central place in the web.config or do I need to change this manually in every instance?
Addition: Would it be possible to do get this date format when restricting the interface to english?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You should build your own culture by using CultureAndRegionInfoBuilder
class Program
{
static void Main(string[] args)
{
CultureInfo ci;
CultureAndRegionInfoBuilder cib = null;
try
{
// Create a CultureAndRegionInfoBuilder object named "x-en-GB".
Console.WriteLine("Create and explore the CultureAndRegionInfoBuilder...n");
cib = new CultureAndRegionInfoBuilder(
"x-en-GB", CultureAndRegionModifiers.None);
// Populate the new CultureAndRegionInfoBuilder object with culture information.
ci = new CultureInfo("en-GB");
ci.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd";
//ci.DateTimeFormat.FullDateTimePattern = "yyyy-MM-dd";
//ci.DateTimeFormat.LongDatePattern = "yyyy-MM-dd";
//...
//...
cib.LoadDataFromCultureInfo(ci);
// Populate the new CultureAndRegionInfoBuilder object with region information.
RegionInfo ri = new RegionInfo("GB");
cib.LoadDataFromRegionInfo(ri);
Console.WriteLine("Register the custom culture...");
cib.Register();
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.WriteLine("Create and explore the custom culture...n");
ci = new CultureInfo("x-en-GB");
//Thread.CurrentThread.CurrentCulture = ci;
//Thread.CurrentThread.CurrentUICulture = ci;
Console.WriteLine(DateTime.Now.ToString(ci));
Console.ReadLine();
}
}
Method 2
If you need the format to be the same across cultures, you will have to set the DateTimeFormat whenever you instantiate a CultureInfo object.
There is no global config option for this.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0