Quiero usar el TimeZoneInfo.FindSystemTimeZoneById(String)
método, pero no sé qué valores usar como entrada.
¿Dónde puedo obtener una lista de valores id
necesarios para FindSystemTimeZoneById
?
Quiero usar el TimeZoneInfo.FindSystemTimeZoneById(String)
método, pero no sé qué valores usar como entrada.
¿Dónde puedo obtener una lista de valores id
necesarios para FindSystemTimeZoneById
?
Respuestas:
Aquí está la lista en Windows 8 (extraje del Registro de Windows)
fuente
GMT Standard Time
( stackoverflow.com/questions/4034923/… ).Puede obtenerlos de una lista estática en la
TimeZoneInfo
clase.var infos = TimeZoneInfo.GetSystemTimeZones(); foreach (var info in infos) { Console.WriteLine(info.Id); }
Ejemplo:
var tzInfo = TimeZoneInfo.FindSystemTimeZoneById("New Zealand Standard Time");
O si solo desea una lista de los identificadores de zona horaria como sugirió DJ KRAZE
var timeZoneIds = TimeZoneInfo.GetSystemTimeZones().Select(t => t.Id);
fuente
Las zonas horarias disponibles son:
Console.WriteLine(string.Join("\n",TimeZoneInfo.GetSystemTimeZones().Select(x=>x.Id)));
Resultado:
Dateline Standard Time UTC-11 Aleutian Standard Time Hawaiian Standard Time Marquesas Standard Time Alaskan Standard Time UTC-09 Pacific Standard Time (Mexico) UTC-08 Pacific Standard Time US Mountain Standard Time Mountain Standard Time (Mexico) Mountain Standard Time Central America Standard Time Central Standard Time Easter Island Standard Time Central Standard Time (Mexico) Canada Central Standard Time SA Pacific Standard Time Eastern Standard Time (Mexico) Eastern Standard Time Haiti Standard Time Cuba Standard Time US Eastern Standard Time Paraguay Standard Time Atlantic Standard Time Venezuela Standard Time Central Brazilian Standard Time SA Western Standard Time Pacific SA Standard Time Turks And Caicos Standard Time Newfoundland Standard Time Tocantins Standard Time E. South America Standard Time SA Eastern Standard Time Argentina Standard Time Greenland Standard Time Montevideo Standard Time Saint Pierre Standard Time Bahia Standard Time UTC-02 Mid-Atlantic Standard Time Azores Standard Time Cape Verde Standard Time UTC Morocco Standard Time GMT Standard Time Greenwich Standard Time W. Europe Standard Time Central Europe Standard Time Romance Standard Time Central European Standard Time W. Central Africa Standard Time Namibia Standard Time Jordan Standard Time GTB Standard Time Middle East Standard Time Egypt Standard Time E. Europe Standard Time Syria Standard Time West Bank Standard Time South Africa Standard Time FLE Standard Time Israel Standard Time Kaliningrad Standard Time Libya Standard Time Arabic Standard Time Turkey Standard Time Arab Standard Time Belarus Standard Time Russian Standard Time E. Africa Standard Time Iran Standard Time Arabian Standard Time Astrakhan Standard Time Azerbaijan Standard Time Russia Time Zone 3 Mauritius Standard Time Georgian Standard Time Caucasus Standard Time Afghanistan Standard Time West Asia Standard Time Ekaterinburg Standard Time Pakistan Standard Time India Standard Time Sri Lanka Standard Time Nepal Standard Time Central Asia Standard Time Bangladesh Standard Time Omsk Standard Time Myanmar Standard Time SE Asia Standard Time Altai Standard Time W. Mongolia Standard Time North Asia Standard Time N. Central Asia Standard Time Tomsk Standard Time China Standard Time North Asia East Standard Time Singapore Standard Time W. Australia Standard Time Taipei Standard Time Ulaanbaatar Standard Time North Korea Standard Time Aus Central W. Standard Time Transbaikal Standard Time Tokyo Standard Time Korea Standard Time Yakutsk Standard Time Cen. Australia Standard Time AUS Central Standard Time E. Australia Standard Time AUS Eastern Standard Time West Pacific Standard Time Tasmania Standard Time Vladivostok Standard Time Lord Howe Standard Time Bougainville Standard Time Russia Time Zone 10 Magadan Standard Time Norfolk Standard Time Sakhalin Standard Time Central Pacific Standard Time Russia Time Zone 11 New Zealand Standard Time UTC+12 Fiji Standard Time Kamchatka Standard Time Chatham Islands Standard Time Tonga Standard Time Samoa Standard Time Line Islands Standard Time
fuente
Eche un vistazo al método estático en el método
TimeZoneInfo
llamadoTimeZoneInfo.GetSystemTimeZones()
.Esto devolverá una lista de todos
TimeZoneInfo
los de su sistema operativo desde el Registro. Todos ellos están almacenados bajo:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
.Un ejemplo es "Hora estándar GMT" para la zona horaria "Dublín, Edimburgo, Lisboa, Londres".
fuente
La última documentación de Microsoft, con una lista de estos, se puede encontrar en https://support.microsoft.com/en-gb/help/973627/microsoft-time-zone-index-values
Las cadenas de ID de zona horaria son actualmente las siguientes (si desea ver la diferencia horaria real de ver el índice hexadecimal para cada ID de zona horaria, haga clic en el enlace anterior):
fuente
Para obtener la lista más actualizada de zonas horarias, use tzutil de Windows:
Aquí puede encontrar la lista oficial de identificadores de zona horaria de Microsoft en MSDN: https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/default-time-zones
fuente
Como han dicho otros, puede encontrar la lista iterando
TimeZoneInfo.GetSystemTimeZones()
para encontrar la cadena que desea usar. Dicho esto, si solo tiene información sobre la diferencia horaria (como GMT + 9 o GMT-10) y no puede encontrar su zona horaria después de iterar las zonas horarias, es posible que desee ver la siguiente URL para ver qué zona horaria necesita https: / /msdn.microsoft.com/en-US/library/ms912391(v=winembedded.11).aspxfuente
O puede pasar de
TimeZoneInfo.Local.Id
esta manera:fuente
Puedes usar ese código a continuación
using System; namespace TimeZoneIds { class Program { static void Main(string[] args) { foreach (TimeZoneInfo z in TimeZoneInfo.GetSystemTimeZones()) Console.WriteLine(z.Id); } } }
fuente
Un método para cambiar de una zona horaria a otra:
DateTime n = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(datetime, "sourceTimeZoneId", "destinationTimeZoneId");
Estoy en Win10 y enumero
Time Zone Id
contime difference
:Dateline Standard Time -12 UTC-11 -11 Hawaiian Standard Time -10 Aleutian Standard Time -9 Marquesas Standard Time -9 UTC-09 -9 Alaskan Standard Time -8 UTC-08 -8 Pacific Standard Time (Mexico) -7 Pacific Standard Time -7 US Mountain Standard Time -7 Mountain Standard Time (Mexico) -6 Mountain Standard Time -6 Central America Standard Time -6 Easter Island Standard Time -6 Canada Central Standard Time -6 Central Standard Time -5 Central Standard Time (Mexico) -5 SA Pacific Standard Time -5 Eastern Standard Time (Mexico) -5 Eastern Standard Time -4 Haiti Standard Time -4 Cuba Standard Time -4 US Eastern Standard Time -4 Turks And Caicos Standard Time -4 Paraguay Standard Time -4 Venezuela Standard Time -4 Central Brazilian Standard Time -4 SA Western Standard Time -4 Pacific SA Standard Time -4 Atlantic Standard Time -3 Tocantins Standard Time -3 E. South America Standard Time -3 SA Eastern Standard Time -3 Argentina Standard Time -3 Montevideo Standard Time -3 Magallanes Standard Time -3 Bahia Standard Time -3 Newfoundland Standard Time -2 Greenland Standard Time -2 Saint Pierre Standard Time -2 UTC-02 -2 Mid-Atlantic Standard Time -1 Cape Verde Standard Time -1 Azores Standard Time 0 UTC 0 Greenwich Standard Time 0 Sao Tome Standard Time 0 GMT Standard Time +1 Morocco Standard Time +1 W. Central Africa Standard Time +1 W. Europe Standard Time +2 Central Europe Standard Time +2 Romance Standard Time +2 Central European Standard Time +2 Egypt Standard Time +2 South Africa Standard Time +2 Kaliningrad Standard Time +2 Sudan Standard Time +2 Libya Standard Time +2 Namibia Standard Time +2 Jordan Standard Time +3 GTB Standard Time +3 Middle East Standard Time +3 E. Europe Standard Time +3 Syria Standard Time +3 West Bank Standard Time +3 FLE Standard Time +3 Israel Standard Time +3 Arabic Standard Time +3 Turkey Standard Time +3 Arab Standard Time +3 Belarus Standard Time +3 Russian Standard Time +3 E. Africa Standard Time +3 Iran Standard Time +4 Arabian Standard Time +4 Astrakhan Standard Time +4 Azerbaijan Standard Time +4 Russia Time Zone 3 +4 Mauritius Standard Time +4 Saratov Standard Time +4 Georgian Standard Time +4 Volgograd Standard Time +4 Caucasus Standard Time +4 Afghanistan Standard Time +4 West Asia Standard Time +5 Ekaterinburg Standard Time +5 Pakistan Standard Time +5 Qyzylorda Standard Time +5 India Standard Time +5 Sri Lanka Standard Time +5 Nepal Standard Time +5 Central Asia Standard Time +6 Bangladesh Standard Time +6 Omsk Standard Time +6 Myanmar Standard Time +6 SE Asia Standard Time +7 Altai Standard Time +7 W. Mongolia Standard Time +7 North Asia Standard Time +7 N. Central Asia Standard Time +7 Tomsk Standard Time +7 China Standard Time +8 North Asia East Standard Time +8 Singapore Standard Time +8 W. Australia Standard Time +8 Taipei Standard Time +8 Ulaanbaatar Standard Time +8 Aus Central W. Standard Time +8 Transbaikal Standard Time +9 Tokyo Standard Time +9 North Korea Standard Time +9 Korea Standard Time +9 Yakutsk Standard Time +9 Cen. Australia Standard Time +9 AUS Central Standard Time +9 E. Australia Standard Time +10 AUS Eastern Standard Time +10 West Pacific Standard Time +10 Tasmania Standard Time +10 Vladivostok Standard Time +10 Lord Howe Standard Time +10 Bougainville Standard Time +11 Russia Time Zone 10 +11 Magadan Standard Time +11 Norfolk Standard Time +11 Sakhalin Standard Time +11 Central Pacific Standard Time +11 Russia Time Zone 11 +12 New Zealand Standard Time +12 UTC+12 +12 Fiji Standard Time +12 Chatham Islands Standard Time +12 Kamchatka Standard Time +13 UTC+13 +13 Tonga Standard Time +13 Samoa Standard Time +13 Line Islands Standard Time +14
Código para obtener la diferencia horaria:
DateTime dt = Convert.ToDateTime("2020-04-17T09:00:00"); Dictionary<string, int> zoneHour = new Dictionary<string, int>(); var infos = TimeZoneInfo.GetSystemTimeZones(); foreach (var info in infos) { zoneHour.Add(info.Id, TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dt, "UTC", info.Id).Subtract(dt).Hours ); } var zoneHourOrder = zoneHour.OrderBy(z => z.Value); foreach (var kv in zoneHourOrder) { Console.WriteLine(kv.Key.PadRight(40) + (kv.Value > 0 ? "+" + kv.Value : kv.Value.ToString())); }
fuente