あなたは辞書を使用することができますが、その後、あなたが持っているだろうホストのオペレーティングシステムのタイムゾーンが更新された場合にそれを維持する(タイムゾーンが変更された場合など... DO変更)。ホストを制御していない場合、これはお尻に本当の痛みかもしれません。私はあなたのためにそれを作った
(あなたが...それin this fiddleをチェックし、すべての定型的なコードを無視することができ、それはMVCのためのdotnetfiddleのデフォルトのコードは、私はちょうどビューを変更します):
@functions{
string GetTimeZonesInEnglish(string timeZoneId, string defaultDisplayName)
{
var dict = new Dictionary<string, string>()
{
{ "Dateline Standard Time"," (UTC-12:00) International Date Line West" },
{ "UTC-11"," (UTC-11:00) Coordinated Universal Time-11" },
{ "Hawaiian Standard Time"," (UTC-10:00) Hawaii" },
{ "Alaskan Standard Time"," (UTC-09:00) Alaska" },
{ "Pacific Standard Time (Mexico)"," (UTC-08:00) Baja California" },
{ "Pacific Standard Time"," (UTC-08:00) Pacific Time (US & Canada)" },
{ "US Mountain Standard Time"," (UTC-07:00) Arizona" },
{ "Mountain Standard Time (Mexico)"," (UTC-07:00) Chihuahua, La Paz, Mazatlan" },
{ "Mountain Standard Time"," (UTC-07:00) Mountain Time (US & Canada)" },
{ "Central America Standard Time"," (UTC-06:00) Central America" },
{ "Central Standard Time"," (UTC-06:00) Central Time (US & Canada)" },
{ "Central Standard Time (Mexico)"," (UTC-06:00) Guadalajara, Mexico City, Monterrey" },
{ "Canada Central Standard Time"," (UTC-06:00) Saskatchewan" },
{ "SA Pacific Standard Time"," (UTC-05:00) Bogota, Lima, Quito, Rio Branco" },
{ "Eastern Standard Time (Mexico)"," (UTC-05:00) Chetumal" },
{ "Eastern Standard Time"," (UTC-05:00) Eastern Time (US & Canada)" },
{ "US Eastern Standard Time"," (UTC-05:00) Indiana (East)" },
{ "Venezuela Standard Time"," (UTC-04:30) Caracas" },
{ "Paraguay Standard Time"," (UTC-04:00) Asuncion" },
{ "Atlantic Standard Time"," (UTC-04:00) Atlantic Time (Canada)" },
{ "Central Brazilian Standard Time"," (UTC-04:00) Cuiaba" },
{ "SA Western Standard Time"," (UTC-04:00) Georgetown, La Paz, Manaus, San Juan" },
{ "Newfoundland Standard Time"," (UTC-03:30) Newfoundland" },
{ "E. South America Standard Time"," (UTC-03:00) Brasilia" },
{ "SA Eastern Standard Time"," (UTC-03:00) Cayenne, Fortaleza" },
{ "Argentina Standard Time"," (UTC-03:00) City of Buenos Aires" },
{ "Greenland Standard Time"," (UTC-03:00) Greenland" },
{ "Montevideo Standard Time"," (UTC-03:00) Montevideo" },
{ "Bahia Standard Time"," (UTC-03:00) Salvador" },
{ "Pacific SA Standard Time"," (UTC-03:00) Santiago" },
{ "UTC-02"," (UTC-02:00) Coordinated Universal Time-02" },
{ "Mid-Atlantic Standard Time"," (UTC-02:00) Mid-Atlantic - Old" },
{ "Azores Standard Time"," (UTC-01:00) Azores" },
{ "Cape Verde Standard Time"," (UTC-01:00) Cabo Verde Is." },
{ "Morocco Standard Time"," (UTC) Casablanca" },
{ "UTC"," (UTC) Coordinated Universal Time" },
{ "GMT Standard Time"," (UTC) Dublin, Edinburgh, Lisbon, London" },
{ "Greenwich Standard Time"," (UTC) Monrovia, Reykjavik" },
{ "W. Europe Standard Time"," (UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna" },
{ "Central Europe Standard Time"," (UTC+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague" },
{ "Romance Standard Time"," (UTC+01:00) Brussels, Copenhagen, Madrid, Paris" },
{ "Central European Standard Time"," (UTC+01:00) Sarajevo, Skopje, Warsaw, Zagreb" },
{ "W. Central Africa Standard Time"," (UTC+01:00) West Central Africa" },
{ "Namibia Standard Time"," (UTC+01:00) Windhoek" },
{ "Jordan Standard Time"," (UTC+02:00) Amman" },
{ "GTB Standard Time"," (UTC+02:00) Athens, Bucharest" },
{ "Middle East Standard Time"," (UTC+02:00) Beirut" },
{ "Egypt Standard Time"," (UTC+02:00) Cairo" },
{ "Syria Standard Time"," (UTC+02:00) Damascus" },
{ "E. Europe Standard Time"," (UTC+02:00) E. Europe" },
{ "South Africa Standard Time"," (UTC+02:00) Harare, Pretoria" },
{ "FLE Standard Time"," (UTC+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius" },
{ "Turkey Standard Time"," (UTC+02:00) Istanbul" },
{ "Israel Standard Time"," (UTC+02:00) Jerusalem" },
{ "Kaliningrad Standard Time"," (UTC+02:00) Kaliningrad (RTZ 1)" },
{ "Libya Standard Time"," (UTC+02:00) Tripoli" },
{ "Arabic Standard Time"," (UTC+03:00) Baghdad" },
{ "Arab Standard Time"," (UTC+03:00) Kuwait, Riyadh" },
{ "Belarus Standard Time"," (UTC+03:00) Minsk" },
{ "Russian Standard Time"," (UTC+03:00) Moscow, St. Petersburg, Volgograd (RTZ 2)" },
{ "E. Africa Standard Time"," (UTC+03:00) Nairobi" },
{ "Iran Standard Time"," (UTC+03:30) Tehran" },
{ "Arabian Standard Time"," (UTC+04:00) Abu Dhabi, Muscat" },
{ "Azerbaijan Standard Time"," (UTC+04:00) Baku" },
{ "Russia Time Zone 3"," (UTC+04:00) Izhevsk, Samara (RTZ 3)" },
{ "Mauritius Standard Time"," (UTC+04:00) Port Louis" },
{ "Georgian Standard Time"," (UTC+04:00) Tbilisi" },
{ "Caucasus Standard Time"," (UTC+04:00) Yerevan" },
{ "Afghanistan Standard Time"," (UTC+04:30) Kabul" },
{ "West Asia Standard Time"," (UTC+05:00) Ashgabat, Tashkent" },
{ "Ekaterinburg Standard Time"," (UTC+05:00) Ekaterinburg (RTZ 4)" },
{ "Pakistan Standard Time"," (UTC+05:00) Islamabad, Karachi" },
{ "India Standard Time"," (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi" },
{ "Sri Lanka Standard Time"," (UTC+05:30) Sri Jayawardenepura" },
{ "Nepal Standard Time"," (UTC+05:45) Kathmandu" },
{ "Central Asia Standard Time"," (UTC+06:00) Astana" },
{ "Bangladesh Standard Time"," (UTC+06:00) Dhaka" },
{ "N. Central Asia Standard Time"," (UTC+06:00) Novosibirsk (RTZ 5)" },
{ "Myanmar Standard Time"," (UTC+06:30) Yangon (Rangoon)" },
{ "SE Asia Standard Time"," (UTC+07:00) Bangkok, Hanoi, Jakarta" },
{ "North Asia Standard Time"," (UTC+07:00) Krasnoyarsk (RTZ 6)" },
{ "China Standard Time"," (UTC+08:00) Beijing, Chongqing, Hong Kong, Urumqi" },
{ "North Asia East Standard Time"," (UTC+08:00) Irkutsk (RTZ 7)" },
{ "Singapore Standard Time"," (UTC+08:00) Kuala Lumpur, Singapore" },
{ "W. Australia Standard Time"," (UTC+08:00) Perth" },
{ "Taipei Standard Time"," (UTC+08:00) Taipei" },
{ "Ulaanbaatar Standard Time"," (UTC+08:00) Ulaanbaatar" },
{ "North Korea Standard Time"," (UTC+08:30) Pyongyang" },
{ "Tokyo Standard Time"," (UTC+09:00) Osaka, Sapporo, Tokyo" },
{ "Korea Standard Time"," (UTC+09:00) Seoul" },
{ "Yakutsk Standard Time"," (UTC+09:00) Yakutsk (RTZ 8)" },
{ "Cen. Australia Standard Time"," (UTC+09:30) Adelaide" },
{ "AUS Central Standard Time"," (UTC+09:30) Darwin" },
{ "E. Australia Standard Time"," (UTC+10:00) Brisbane" },
{ "AUS Eastern Standard Time"," (UTC+10:00) Canberra, Melbourne, Sydney" },
{ "West Pacific Standard Time"," (UTC+10:00) Guam, Port Moresby" },
{ "Tasmania Standard Time"," (UTC+10:00) Hobart" },
{ "Magadan Standard Time"," (UTC+10:00) Magadan" },
{ "Vladivostok Standard Time"," (UTC+10:00) Vladivostok, Magadan (RTZ 9)" },
{ "Russia Time Zone 10"," (UTC+11:00) Chokurdakh (RTZ 10)" },
{ "Central Pacific Standard Time"," (UTC+11:00) Solomon Is., New Caledonia" },
{ "Russia Time Zone 11"," (UTC+12:00) Anadyr, Petropavlovsk-Kamchatsky (RTZ 11)" },
{ "New Zealand Standard Time"," (UTC+12:00) Auckland, Wellington" },
{ "UTC+12"," (UTC+12:00) Coordinated Universal Time+12" },
{ "Fiji Standard Time"," (UTC+12:00) Fiji" },
{ "Kamchatka Standard Time"," (UTC+12:00) Petropavlovsk-Kamchatsky - Old" },
{ "Tonga Standard Time"," (UTC+13:00) Nuku'alofa" },
{ "Samoa Standard Time"," (UTC+13:00) Samoa" },
{ "Line Islands Standard Time"," (UTC+14:00) Kiritimati Island" },
};
string retVal;
if(dict.TryGetValue(timeZoneId, out retVal))
return retVal;
return defaultDisplayName;
}
}
そして、その後:
<select id="timezone" name="timezone">
@foreach (var timeZone in TimeZoneInfo.GetSystemTimeZones()) {
<option value="@timeZone.Id">@GetTimeZonesInEnglish(timeZone.Id, timeZone.DisplayName)</option>
}
</select>
私はあなたがそれらを更新したいだけの場合には、英語のマシンから「辞書初期化フォーマット」の文字列を出力するいくつかの簡単なコンソールユーティリティを作っ:
私は上記の言ったことをしながら、
タイムゾーン名を表示するので、すべてこれは、言っin this fiddle
を、それをチェックアウトが...ホストのオペレーティングシステムのレジストリを使用して発見し、言語に依存しているしている彼らならば決して「働きません」更新、私はそれを処理するための最良の方法ではないと言いたいと思います。私は私のホストの制御になかった場合、私は個人的に自分のタイムゾーンを処理したい
あなたはそれをdatamineまでであれば、私のデータベースまたは任意に...あなたは、更新タイムゾーンデータベースin the IANAまたはwikipedia中に見つけることができます。
(多くの冗長タイムゾーンを無視して)ユーザーにタイムゾーンを示すに一般的に適していると多くの言語での(簡単に解析可能な)XMLファイル
を提供し、もちろん、ありますユニコードからCommon Locale Data RepositoryもありますまたNoda Timeで、Jon Skeet(その他)以外にもチェックしてください。私はだと思います。それは独自のOlsonタイムゾーンデータベースを維持していますが、私はこれをすべて確信しているわけではありません。
この問題に関連する可能性があります:http://stackoverflow.com/questions/13163241/getting-system-timezones-in-different-languages – greenshade
私はホスティング環境で私のサイトをホストする許可を持っていますが、任意の言語パックをインストールするための許可。 – Hoque
はい、.NETのグローバリゼーション機能ではなく、OSのローカリゼーションに依存しています。これは[the timezone tag wiki](http://stackoverflow.com/tags/timezone/info)に記載されています。また、[この件に関する私のブログ](http://codeofmatt.com/2014/12/26/localized-time-zone-names-in-net/)を見て[このライブラリ](http:// mj1856.github.io/TimeZoneNames/)を参照してください。 –