Newbie here. Actually, first question ever.
I've been using NodaTime (on ASP.Net MVC 3 C#) to get around different time zones and am really happy with the results. But... I was wondering if there's a way to get the user's culture info based on the time zone - ie: to display the date/time.
Thanks in advance for any help!
UPDATE
Let me be more clear on this...
I'm able to determine the user time zone using jsTimeZoneDetect and NodaTime. It's working perfectly. Now, what I need is to find out the user locale info (date/time format, etc) to be able to display these info correctly. ie: An user based on US would see the date as 3/21/2013.
I've tried to obtain the locale from the Request.UserLanguages with no avail. IE returns my locale correctly (en-GB), but both Firefox and Chrome are always returning en-US. I've also changed the web.config and added the following element:
<globalization culture="auto" uiCulture="auto" enableClientBasedCulture="true" />
And that's the piece of code I've been working on:
var userLanguages = Request.UserLanguages;
CultureInfo ci;
if (userLanguages.Length > 0)
{
try
{
ci = new CultureInfo(userLanguages[0]);
}
catch (CultureNotFoundException)
{
ci = CultureInfo.InvariantCulture;
}
}
else
{
ci = CultureInfo.InvariantCulture;
}
string cultureName = ci.Name /* Always returns en-US */
Just as another point, to ask the user to select their locale info is not an option for me. ie: DropdownList on the site, etc.
Any further help? Thanks in advance.
UPDATE 2
Following @JonSkeet advice, I've changed the question title and labels to fit my issue better.
UPDATE 3
Just found out something. The way the language (locale) is returned, depends on the browser, as follows:
- Internet Explorer returns the language set on the OS settings, or the browser ones.
- Firefox, Chrome, Safari and Opera return the language set on the browser settings.
Considering this, I can't even think about using this information as it comes, because there's no way to guarantee that every single user will change their browser settings. The only info I could rely on is the one coming from the OS settings.
I don't have a clue on what to do now.