Reputation: 147
I am looking for a way to set date format in either mm/dd/yyyy or dd/mm/yyyy . Setting culture for my pages based on ip sets the language of asp.net calendar in local language. For eg: it works fine for US , Australia , Uk. But for countries like Saudi Arabia I want my calendar to be still in English and not its local language like Arabic.
I basically want my calendar to be in English but with the correct format.
Please have a look at the code.
P.S., This code works fine for India where they have "en" as TwoLetterISOLanguageName. But then I realised not all countries have "en".
private static CultureInfo GetCultureInfo(UserSession currentUserSession, string userHostAddress)
{
try
{
string location = null;
// use logged in user's configured location
if (currentUserSession != null)
{
location = currentUserSession.LocationString;
}
// fall back to IP address
if (string.IsNullOrEmpty(location))
{
string code = IPToCountry.GetCountry(userHostAddress);
if (code != null)
{
location = Config.Users.GetCountryByCode(code);
}
}
// find english culture for country, if it exists
if (!string.IsNullOrEmpty(location))
{
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
try
{
if (ci.TwoLetterISOLanguageName == "en")
{
RegionInfo ri = new RegionInfo(ci.LCID);
if (location.Contains(ri.EnglishName))
return ci;
}
}
catch (Exception)
{
}
}
}
}
catch (Exception)
{
}
return null;
}
Upvotes: 0
Views: 441
Reputation: 57182
I'm not sure I understood your question correctly, but you can set explicitly the format for dates in a culture.
Note that you need to clone a CultureInfo
before being able to set the DateTimeFormat
property.
Upvotes: 2