Why is this giving me 2 different sets of timezones?

旧巷老猫 提交于 2019-12-10 22:19:53

问题


Edit

I believe this is a issue with I am using windows 7 and my server is windows 2008. I think windows 2008 uses still GMT. So how could I get around this issue. Like I want to deal in UTC but I want to have the default selected item to be "Coordinated Universal Time" what is not in the gmt list but in the UTC list.

So I am not sure what to do. (I am not a shared host so if you can change it on windows 2008 machine it won't help me much).

Hi

I have this line to get all the timezones

 Dictionary<string, TimeZoneInfo> storeZoneName = TimeZoneInfo.GetSystemTimeZones().ToDictionary(z => z.DisplayName);

Now when I upload I try it on my local machine I get this

(UTC-12:00) International Date Line West
(UTC-11:00) Coordinated Universal Time-11
(UTC-11:00) Samoa
(UTC-10:00) Hawaii
(UTC-09:00) Alaska
(UTC-08:00) Baja California
(UTC-08:00) Pacific Time (US & Canada)
(UTC-07:00) Arizona
(UTC-07:00) Chihuahua, La Paz, Mazatlan
(UTC-07:00) Mountain Time (US & Canada)
(UTC-06:00) Central America
(UTC-06:00) Central Time (US & Canada)
(UTC-06:00) Guadalajara, Mexico City, Monterrey
(UTC-06:00) Saskatchewan
(UTC-05:00) Bogota, Lima, Quito
(UTC-05:00) Eastern Time (US & Canada)
(UTC-05:00) Indiana (East)
(UTC-04:30) Caracas
(UTC-04:00) Asuncion
(UTC-04:00) Atlantic Time (Canada)
(UTC-04:00) Cuiaba
(UTC-04:00) Georgetown, La Paz, Manaus, San Juan
(UTC-04:00) Santiago
(UTC-03:30) Newfoundland
(UTC-03:00) Brasilia
(UTC-03:00) Buenos Aires
(UTC-03:00) Cayenne, Fortaleza
(UTC-03:00) Greenland
(UTC-03:00) Montevideo
(UTC-02:00) Coordinated Universal Time-02
(UTC-02:00) Mid-Atlantic
(UTC-01:00) Azores
(UTC-01:00) Cape Verde Is.
(UTC) Casablanca
(UTC) Coordinated Universal Time
(UTC) Dublin, Edinburgh, Lisbon, London
(UTC) Monrovia, Reykjavik
(UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna
(UTC+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague
(UTC+01:00) Brussels, Copenhagen, Madrid, Paris
(UTC+01:00) Sarajevo, Skopje, Warsaw, Zagreb
(UTC+01:00) West Central Africa
(UTC+02:00) Amman
(UTC+02:00) Athens, Bucharest, Istanbul
(UTC+02:00) Beirut
(UTC+02:00) Cairo
(UTC+02:00) Harare, Pretoria
(UTC+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius
(UTC+02:00) Jerusalem
(UTC+02:00) Minsk
(UTC+02:00) Windhoek
(UTC+03:00) Baghdad
(UTC+03:00) Kuwait, Riyadh
(UTC+03:00) Moscow, St. Petersburg, Volgograd
(UTC+03:00) Nairobi
(UTC+03:30) Tehran
(UTC+04:00) Abu Dhabi, Muscat
(UTC+04:00) Baku
(UTC+04:00) Port Louis
(UTC+04:00) Tbilisi
(UTC+04:00) Yerevan
(UTC+04:30) Kabul
(UTC+05:00) Ekaterinburg
(UTC+05:00) Islamabad, Karachi
(UTC+05:00) Tashkent
(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi
(UTC+05:30) Sri Jayawardenepura
(UTC+05:45) Kathmandu
(UTC+06:00) Astana
(UTC+06:00) Dhaka
(UTC+06:00) Novosibirsk
(UTC+06:30) Yangon (Rangoon)
(UTC+07:00) Bangkok, Hanoi, Jakarta
(UTC+07:00) Krasnoyarsk
(UTC+08:00) Beijing, Chongqing, Hong Kong, Urumqi
(UTC+08:00) Irkutsk
(UTC+08:00) Kuala Lumpur, Singapore
(UTC+08:00) Perth
(UTC+08:00) Taipei
(UTC+08:00) Ulaanbaatar
(UTC+09:00) Osaka, Sapporo, Tokyo
(UTC+09:00) Seoul
(UTC+09:00) Yakutsk
(UTC+09:30) Adelaide
(UTC+09:30) Darwin
(UTC+10:00) Brisbane
(UTC+10:00) Canberra, Melbourne, Sydney
(UTC+10:00) Guam, Port Moresby
(UTC+10:00) Hobart
(UTC+10:00) Vladivostok
(UTC+11:00) Magadan, Solomon Is., New Caledonia
(UTC+12:00) Auckland, Wellington
(UTC+12:00) Coordinated Universal Time+12
(UTC+12:00) Fiji
(UTC+12:00) Petropavlovsk-Kamchatsky
(UTC+13:00) Nuku'alofa

When I run it on a different local machine or my server I have this.

<option value="(GMT) Casablanca">(GMT) Casablanca</option>
<option value="(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London">(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London</option>
<option value="(GMT) Monrovia, Reykjavik">(GMT) Monrovia, Reykjavik</option>
<option value="(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna">(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna</option>
<option value="(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague">(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague</option>
<option value="(GMT+01:00) Brussels, Copenhagen, Madrid, Paris">(GMT+01:00) Brussels, Copenhagen, Madrid, Paris</option>
<option value="(GMT+01:00) Sarajevo, Skopje, Warsaw, Zagreb">(GMT+01:00) Sarajevo, Skopje, Warsaw, Zagreb</option>
<option value="(GMT+01:00) West Central Africa">(GMT+01:00) West Central Africa</option>
<option value="(GMT+02:00) Amman">(GMT+02:00) Amman</option>
<option value="(GMT+02:00) Athens, Bucharest, Istanbul">(GMT+02:00) Athens, Bucharest, Istanbul</option>
<option value="(GMT+02:00) Beirut">(GMT+02:00) Beirut</option>
<option value="(GMT+02:00) Cairo">(GMT+02:00) Cairo</option>
<option value="(GMT+02:00) Harare, Pretoria">(GMT+02:00) Harare, Pretoria</option>
<option value="(GMT+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius">(GMT+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius</option>
<option value="(GMT+02:00) Jerusalem">(GMT+02:00) Jerusalem</option>
<option value="(GMT+02:00) Minsk">(GMT+02:00) Minsk</option>
<option value="(GMT+02:00) Windhoek">(GMT+02:00) Windhoek</option>
<option value="(GMT+03:00) Baghdad">(GMT+03:00) Baghdad</option>
<option value="(GMT+03:00) Kuwait, Riyadh">(GMT+03:00) Kuwait, Riyadh</option>
<option value="(GMT+03:00) Moscow, St. Petersburg, Volgograd">(GMT+03:00) Moscow, St. Petersburg, Volgograd</option>
<option value="(GMT+03:00) Nairobi">(GMT+03:00) Nairobi</option>
<option value="(GMT+03:00) Tbilisi">(GMT+03:00) Tbilisi</option>
<option value="(GMT+03:30) Tehran">(GMT+03:30) Tehran</option>
<option value="(GMT+04:00) Abu Dhabi, Muscat">(GMT+04:00) Abu Dhabi, Muscat</option>
<option value="(GMT+04:00) Baku">(GMT+04:00) Baku</option>
<option value="(GMT+04:00) Port Louis">(GMT+04:00) Port Louis</option>
<option value="(GMT+04:00) Yerevan">(GMT+04:00) Yerevan</option>
<option value="(GMT+04:30) Kabul">(GMT+04:30) Kabul</option>
<option value="(GMT+05:00) Ekaterinburg">(GMT+05:00) Ekaterinburg</option>
<option value="(GMT+05:00) Islamabad, Karachi">(GMT+05:00) Islamabad, Karachi</option>
<option value="(GMT+05:00) Tashkent">(GMT+05:00) Tashkent</option>
<option value="(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi">(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi</option>
<option value="(GMT+05:30) Sri Jayawardenepura">(GMT+05:30) Sri Jayawardenepura</option>
<option value="(GMT+05:45) Kathmandu">(GMT+05:45) Kathmandu</option>
<option value="(GMT+06:00) Almaty, Novosibirsk">(GMT+06:00) Almaty, Novosibirsk</option>
<option value="(GMT+06:00) Astana, Dhaka">(GMT+06:00) Astana, Dhaka</option>
<option value="(GMT+06:30) Yangon (Rangoon)">(GMT+06:30) Yangon (Rangoon)</option>
<option value="(GMT+07:00) Bangkok, Hanoi, Jakarta">(GMT+07:00) Bangkok, Hanoi, Jakarta</option>
<option value="(GMT+07:00) Krasnoyarsk">(GMT+07:00) Krasnoyarsk</option>
<option value="(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi">(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi</option>
<option value="(GMT+08:00) Irkutsk, Ulaan Bataar">(GMT+08:00) Irkutsk, Ulaan Bataar</option>
<option value="(GMT+08:00) Kuala Lumpur, Singapore">(GMT+08:00) Kuala Lumpur, Singapore</option>
<option value="(GMT+08:00) Perth">(GMT+08:00) Perth</option>
<option value="(GMT+08:00) Taipei">(GMT+08:00) Taipei</option>
<option value="(GMT+09:00) Osaka, Sapporo, Tokyo">(GMT+09:00) Osaka, Sapporo, Tokyo</option>
<option value="(GMT+09:00) Seoul">(GMT+09:00) Seoul</option>
<option value="(GMT+09:00) Yakutsk">(GMT+09:00) Yakutsk</option>
<option value="(GMT+09:30) Adelaide">(GMT+09:30) Adelaide</option>
<option value="(GMT+09:30) Darwin">(GMT+09:30) Darwin</option>
<option value="(GMT+10:00) Brisbane">(GMT+10:00) Brisbane</option>
<option value="(GMT+10:00) Canberra, Melbourne, Sydney">(GMT+10:00) Canberra, Melbourne, Sydney</option>
<option value="(GMT+10:00) Guam, Port Moresby">(GMT+10:00) Guam, Port Moresby</option>
<option value="(GMT+10:00) Hobart">(GMT+10:00) Hobart</option>
<option value="(GMT+10:00) Vladivostok">(GMT+10:00) Vladivostok</option>
<option value="(GMT+11:00) Magadan, Solomon Is., New Caledonia">(GMT+11:00) Magadan, Solomon Is., New Caledonia</option>
<option value="(GMT+12:00) Auckland, Wellington">(GMT+12:00) Auckland, Wellington</option>
<option value="(GMT+12:00) Fiji, Kamchatka, Marshall Is.">(GMT+12:00) Fiji, Kamchatka, Marshall Is.</option>
<option value="(GMT+13:00) Nuku'alofa">(GMT+13:00) Nuku'alofa</option>
<option value="(GMT-01:00) Azores">(GMT-01:00) Azores</option>
<option value="(GMT-01:00) Cape Verde Is.">(GMT-01:00) Cape Verde Is.</option>
<option value="(GMT-02:00) Mid-Atlantic">(GMT-02:00) Mid-Atlantic</option>
<option value="(GMT-03:00) Brasilia">(GMT-03:00) Brasilia</option>
<option value="(GMT-03:00) Buenos Aires">(GMT-03:00) Buenos Aires</option>
<option value="(GMT-03:00) Georgetown">(GMT-03:00) Georgetown</option>
<option value="(GMT-03:00) Greenland">(GMT-03:00) Greenland</option>
<option value="(GMT-03:00) Montevideo">(GMT-03:00) Montevideo</option>
<option value="(GMT-03:30) Newfoundland">(GMT-03:30) Newfoundland</option>
<option value="(GMT-04:00) Atlantic Time (Canada)">(GMT-04:00) Atlantic Time (Canada)</option>
<option value="(GMT-04:00) La Paz">(GMT-04:00) La Paz</option>
<option value="(GMT-04:00) Manaus">(GMT-04:00) Manaus</option>
<option value="(GMT-04:00) Santiago">(GMT-04:00) Santiago</option>
<option value="(GMT-04:30) Caracas">(GMT-04:30) Caracas</option>
<option value="(GMT-05:00) Bogota, Lima, Quito, Rio Branco">(GMT-05:00) Bogota, Lima, Quito, Rio Branco</option>
<option value="(GMT-05:00) Eastern Time (US &amp; Canada)">(GMT-05:00) Eastern Time (US &amp; Canada)</option>
<option value="(GMT-05:00) Indiana (East)">(GMT-05:00) Indiana (East)</option>
<option value="(GMT-06:00) Central America">(GMT-06:00) Central America</option>
<option value="(GMT-06:00) Central Time (US &amp; Canada)">(GMT-06:00) Central Time (US &amp; Canada)</option>
<option value="(GMT-06:00) Guadalajara, Mexico City, Monterrey">(GMT-06:00) Guadalajara, Mexico City, Monterrey</option>
<option value="(GMT-06:00) Saskatchewan">(GMT-06:00) Saskatchewan</option>
<option value="(GMT-07:00) Arizona">(GMT-07:00) Arizona</option>
<option value="(GMT-07:00) Chihuahua, La Paz, Mazatlan">(GMT-07:00) Chihuahua, La Paz, Mazatlan</option>
<option value="(GMT-07:00) Mountain Time (US &amp; Canada)">(GMT-07:00) Mountain Time (US &amp; Canada)</option>
<option value="(GMT-08:00) Pacific Time (US &amp; Canada)">(GMT-08:00) Pacific Time (US &amp; Canada)</option>
<option value="(GMT-08:00) Tijuana, Baja California">(GMT-08:00) Tijuana, Baja California</option>
<option value="(GMT-09:00) Alaska">(GMT-09:00) Alaska</option>
<option value="(GMT-10:00) Hawaii">(GMT-10:00) Hawaii</option>
<option value="(GMT-11:00) Midway Island, Samoa">(GMT-11:00) Midway Island, Samoa</option>
<option value="(GMT-12:00) International Date Line West">(GMT-12:00) International Date Line West</option>

They are different. Same line of code but one is GMT and one is UTC. How can I force it to be always the same?

Also I want to have a default choice of "UTC" but I am not sure what the diff is between this

(UTC-11:00) Coordinated Universal Time-11

and this

  (UTC-02:00) Coordinated Universal Time-02

回答1:


GMT and UTC are the same thing. I guess one system is set to English (US) and one to English (UK) (or some other combination, perhaps).

(UTC-11:00) Coordinated Universal Time-11

This means "11 hours behind UTC".

(UTC-02:00) Coordinated Universal Time-02

This means "2 hours behind UTC"

That is to say, if UTC is 4:32 PM, then UTC-02:00 would be 2:32 PM and UTC-11:00 would be 5:32 AM.




回答2:


The problem is that you are using the DisplayName of the time-zones, this is just a label and should not be used to id the timezone! As TimeZoneInfo.GetSystemTimeZones() enumerates the timezones on your local system, the DisplayNames are different, depending on which OS you are running the program.

Systems older than Windows Vista/2008 Server displayed the the timezones as GMT+XX:XX but the new Systems use the UTC+XX:XX style. But this is not the only difference; in some timezones there are also differences in the listed cities and the listed city names are localized!

E. g. the timezone id'd "Arab Standard Time" is displayed as:
(GMT+03:00) Kuwait, Er Riad at a German XP/2003 System, but it is
(UTC+03:00) Kuwait, Riyadh at a English Win 7 System.

And "Central Standard Time" is listed as:
(GMT-06:00) Chicago, Dallas, Kansas City, Winnipeg - GER XP/2003
(UTC-06:00) Central Time (US & Canada) - ENG Win 7

Just exchanging GMT and UTC might work in some cases, but it will not always work and can lead to unexpected errors! So don't do it!

You should instead us the Id property, to identify the time zone and uses the DisplayName only for display purposes (as the name suggests).

The Id represents the key of the timezone, like it is stored at the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones and it will work across different OS-Versions and -Languages.



来源:https://stackoverflow.com/questions/2917534/why-is-this-giving-me-2-different-sets-of-timezones

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