Saya ingin menggunakan TimeZoneInfo.FindSystemTimeZoneById(String)
metode ini, tetapi saya tidak tahu nilai apa yang akan digunakan sebagai input?
Di mana saya bisa mendapatkan daftar nilai yang id
diperlukan untuk FindSystemTimeZoneById
?
Saya ingin menggunakan TimeZoneInfo.FindSystemTimeZoneById(String)
metode ini, tetapi saya tidak tahu nilai apa yang akan digunakan sebagai input?
Di mana saya bisa mendapatkan daftar nilai yang id
diperlukan untuk FindSystemTimeZoneById
?
Jawaban:
Berikut adalah daftar di Windows 8 (saya ekstrak dari Windows Registry)
sumber
GMT Standard Time
( stackoverflow.com/questions/4034923/… ).Anda dapat mengambilnya dari daftar statis di
TimeZoneInfo
kelasvar infos = TimeZoneInfo.GetSystemTimeZones(); foreach (var info in infos) { Console.WriteLine(info.Id); }
Contoh:
var tzInfo = TimeZoneInfo.FindSystemTimeZoneById("New Zealand Standard Time");
Atau jika Anda hanya ingin daftar id zona waktu seperti yang disarankan DJ KRAZE
var timeZoneIds = TimeZoneInfo.GetSystemTimeZones().Select(t => t.Id);
sumber
Zona waktu yang tersedia adalah:
Console.WriteLine(string.Join("\n",TimeZoneInfo.GetSystemTimeZones().Select(x=>x.Id)));
Hasil:
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
sumber
Lihat metode statis yang
TimeZoneInfo
dipanggilTimeZoneInfo.GetSystemTimeZones()
.Ini akan mengembalikan daftar semua yang ada
TimeZoneInfo
di sistem operasi Anda dari Registry. Semuanya disimpan di bawah:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
.Contohnya adalah "Waktu Standar GMT" untuk zona waktu "Dublin, Edinburgh, Lisbon, London".
sumber
Dokumentasi Microsoft terbaru, dengan daftarnya, dapat ditemukan di https://support.microsoft.com/en-gb/help/973627/microsoft-time-zone-index-values
String ID zona waktu saat ini adalah sebagai berikut (jika Anda ingin melihat perbedaan waktu sebenarnya, lihat indeks hex untuk setiap ID zona waktu, lalu klik tautan di atas):
sumber
Untuk mendapatkan daftar zona waktu terbaru, gunakan tzutil dari Windows:
Di sini Anda dapat menemukan daftar ID Zona Waktu resmi dari Microsoft di MSDN: https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/default-time-zones
sumber
Seperti yang dikatakan orang lain, Anda dapat menemukan daftar dengan mengulang
TimeZoneInfo.GetSystemTimeZones()
untuk menemukan string yang ingin Anda gunakan. Meskipun demikian, jika Anda hanya memiliki informasi tentang perbedaan waktu (seperti GMT + 9 atau GMT-10) dan tidak dapat menemukan zona waktu Anda setelah mengulang Zona Waktu, Anda mungkin ingin melihat url berikut untuk melihat zona waktu mana yang Anda perlukan https: / /msdn.microsoft.com/en-US/library/ms912391(v=winembedded.11).aspxsumber
Atau Anda bisa melewati
TimeZoneInfo.Local.Id
seperti ini:sumber
Anda dapat menggunakan kode di bawah ini
using System; namespace TimeZoneIds { class Program { static void Main(string[] args) { foreach (TimeZoneInfo z in TimeZoneInfo.GetSystemTimeZones()) Console.WriteLine(z.Id); } } }
sumber
Sebuah metode untuk berpindah dari satu zona waktu ke zona waktu lainnya:
DateTime n = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(datetime, "sourceTimeZoneId", "destinationTimeZoneId");
Saya menggunakan Win10, dan saya mendaftar
Time Zone Id
dengantime 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
Kode untuk mendapatkan perbedaan waktu:
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())); }
sumber