In my C# console (.NET Core) application, I am saving user TimeZoneId (e.g. Bangladesh Standard Time) into the database. Now based on this timezone ID I would like to get current culture info. More specifically I would like to have 2-letter ISO Name (e.g. BD, US, UK). I can use the below code to get current culture info to get my 2-letter ISO Name. But it always shows - en. The reason maybe I have set the language settings to English from the Contol Panel in my Windows 10. So I am not finding the expected output. This is why I would like to get the culture info based on TimeZoneId as it is saved into the database. The code I have used to get current culture:
CultureInfo ci = CultureInfo.InstalledUICulture;
Console.WriteLine("Default Language Info:");
Console.WriteLine("* Name: {0}", ci.Name);
Console.WriteLine("* Display Name: {0}", ci.DisplayName);
Console.WriteLine("* English Name: {0}", ci.EnglishName);
Console.WriteLine("* 2-letter ISO Name: {0}", ci.TwoLetterISOLanguageName);
Console.WriteLine("* 3-letter ISO Name: {0}", ci.ThreeLetterISOLanguageName);
Current output:
Can anyone give me a C# example to get my solution?
Time zone and culture/locale are orthogonal concepts. They are completely disconnected. One cannot tell the culture from the time zone or vice versa.
For example, I may be an English speaking American (culture code en-US
), but I may be traveling or living in Japan (IANA time zone Asia/Tokyo
, Windows time zone ID Tokyo Standard Time
).
To be more specific in .NET:
CultureInfo.CurrentCulture // how do you want your numbers and dates to be formatted?
CultureInfo.CurrentUICulture // what language and dialect do you speak?
TimeZoneInfo.Local.Id // what time zone are you observing? (on the local computer)