How to convert the standard Noda Timezone Id's from English to Localized Language?

ぃ、小莉子 提交于 2019-12-04 08:55:10

This isn't a current feature of Noda Time, so you will need to get the data elsewhere.

Localizations for time zones (and other items) are best found within the Unicode CLDR project. You can write code to parse the various XML files included with the CLDR releases. You'll also need to understand how the data is represented, and several edge cases.

Or, you can use the implementation that I've already completed.

Install the TimeZoneNames Nuget package:

PM>  Install-Package TimeZoneNames

Then you can easily resolve the time zone names to a localized display value:

// example input values
var names = TZNames.GetNamesForTimeZone("America/Los_Angeles", "en-US");

// example output values
Assert.Equal("Pacific Time", names.Generic);
Assert.Equal("Pacific Standard Time", names.Standard);
Assert.Equal("Pacific Daylight Time", names.Daylight);

This works for non-English locales as well. It will produce valid text in any language, provided that the data exists in the CLDR.

The same library can also be used to get a list of time zone ids for a particular country. This can be used to implement a two-dropdown selection list, where first you pick the country, and then you pick the time zone within the country.

var zones = TZNames.GetTimeZoneIdsForCountry("US");

You can take a look at the project's unit tests for further examples.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!