Reputation: 63
I am currently getting TimeZone using
string TimeZoneName = "Indian Standard Time";
var tz = TimeZoneInfo.FindSystemTimeZoneById(TimeZoneName);
It is currently returning the desired value in English even if I change the Current culture and I am currently testing the code on Azure (Web App Service). Please help me to find a way in which I can get the code to return value in Different language like Arabic, French, etc.
Upvotes: 4
Views: 1982
Reputation: 167
TimeZoneInfo timeZone = TimeZoneInfo.GetSystemTimeZones().SingleOrDefault(z => z.DaylightName == TimeZone.CurrentTimeZone.DaylightName);
This will return the current timezone based on the OS language.
Upvotes: 2
Reputation: 3012
You can install the nuget package : https://github.com/mj1856/TimeZoneNames
PM> Install-Package TimeZoneNames
It' a simple library that provides localized time zone names using CLDR and TZDB sources.
Example:
var names = TZNames.GetNamesForTimeZone("Romance Standard Time", "en-GB");
names.Generic == "Central European Time"
names.Standard == "Central European Standard Time"
names.Daylight == "Central European Summer Time"
Upvotes: 1
Reputation: 62159
This is because you are not dealing with a NAME, but an ID.
TimeZoneInfo.FindSystemTimeZoneById
Read the method name. It does not say "by name" but "by id". The ID is meant to be the same across all languages.
What you can do is go across all timezones and compared names (Display Name) likely, then take the one you want. The names is localized:
https://msdn.microsoft.com/en-us/library/system.timezoneinfo.displayname(v=vs.110).aspx
The display name is localized based on the culture installed with the Windows operating system.
But the ID does not never ever change. On purpose.
Upvotes: 0