最近在项目中Fix了一个跨时区的bug,为了Fix这个bug真是费了九牛二虎之力呀。就现在看来主要原因还是平时的开发任务没有涉及到这方面的概念,并且测试跨时区功能的Test Case也比较的难写。为了以后能顺利的解决跨时区功能的问题,制作了张跨时区表,总共102个时区:
UTC时区表
Dateline Standard Time|UTC-12:00 | UTC-11|UTC-11:00 | Hawaiian Standard Time|UTC-10:00 |
Alaskan Standard Time|UTC-09:00 | Pacific Standard Time (Mexico)|UTC-08:00 | Pacific Standard Time|UTC-08:00 |
US Mountain Standard Time|UTC-07:00 | Mountain Standard Time (Mexico)|UTC-07:00 | Mountain Standard Time|UTC-07:00 |
Central America Standard Time|UTC-06:00 | Central Standard Time|UTC-06:00 | Central Standard Time (Mexico)|UTC-06:00 |
Canada Central Standard Time|UTC-06:00 | SA Pacific Standard Time|UTC-05:00 | Eastern Standard Time|UTC-05:00 |
US Eastern Standard Time|UTC-05:00 | Venezuela Standard Time|UTC-04:30 | Paraguay Standard Time|UTC-04:00 |
Atlantic Standard Time|UTC-04:00 | Central Brazilian Standard Time|UTC-04:00 | SA Western Standard Time|UTC-04:00 |
Pacific SA Standard Time|UTC-04:00 | Newfoundland Standard Time|UTC-03:30 | E. South America Standard Time|UTC-03:00 |
Argentina Standard Time|UTC-03:00 | SA Eastern Standard Time|UTC-03:00 | Greenland Standard Time|UTC-03:00 |
Montevideo Standard Time|UTC-03:00 | Bahia Standard Time|UTC-03:00 | UTC-02|UTC-02:00 |
Mid-Atlantic Standard Time|UTC-02:00 | Azores Standard Time|UTC-01:00 | Cape Verde Standard Time|UTC-01:00 |
Morocco Standard Time|UTC | Coordinated Universal Time|UTC | GMT Standard Time|UTC |
Greenwich Standard Time|UTC | W. Europe Standard Time|UTC+01:00</td> | Central Europe Standard Time|UTC+01:00 |
Romance Standard Time|UTC+01:00 | Central European Standard Time|UTC+01:00 | Libya Standard Time|UTC+01:00 |
W. Central Africa Standard Time|UTC+01:00 | Namibia Standard Time|UTC+01:00 | GTB Standard Time|UTC+02:00 |
Middle East Standard Time|UTC+02:00 | Egypt Standard Time|UTC+02:00 | Syria Standard Time|UTC+02:00 |
E. Europe Standard Time|UTC+02:00 | South Africa Standard Time|UTC+02:00 | FLE Standard Time|UTC+02:00 |
Turkey Standard Time|UTC+02:00 | Jerusalem Standard Time|UTC+02:00 | Jordan Standard Time|UTC+03:00 |
Arabic Standard Time|UTC+03:00 | Kaliningrad Standard Time|UTC+03:00 | Arab Standard Time|UTC+03:00 |
E. Africa Standard Time|UTC+03:00 | Iran Standard Time|UTC+03:30</td> | Arabian Standard Time|UTC+04:00 |
Azerbaijan Standard Time|UTC+04:00 | Russian Standard Time|UTC+04:00 | Mauritius Standard Time|UTC+04:00 |
Georgian Standard Time|UTC+04:00 | Caucasus Standard Time|UTC+04:00 | Afghanistan Standard Time|UTC+04:30 |
Pakistan Standard Time|UTC+05:00 | West Asia Standard Time|UTC+05:00 | India Standard Time|UTC+05:30 |
Sri Lanka Standard Time|UTC+05:30 | Nepal Standard Time|UTC+05:45</td> | Central Asia Standard Time|UTC+06:00 |
Bangladesh Standard Time|UTC+06:00 | Ekaterinburg Standard Time|UTC+06:00 | Myanmar Standard Time|UTC+06:30 |
SE Asia Standard Time|UTC+07:00 | N. Central Asia Standard Time|UTC+07:00 | China Standard Time|UTC+08:00 |
North Asia Standard Time|UTC+08:00 | Malay Peninsula Standard Time|UTC+08:00 | W. Australia Standard Time|UTC+08:00 |
Taipei Standard Time|UTC+08:00 | Ulaanbaatar Standard Time|UTC+08:00 | North Asia East Standard Time|UTC+09:00 |
Tokyo Standard Time|UTC+09:00 | Korea Standard Time|UTC+09:00 | Cen. Australia Standard Time|UTC+09:30 |
AUS Central Standard Time|UTC+09:30 | E. Australia Standard Time|UTC+10:00 | AUS Eastern Standard Time|UTC+10:00 |
West Pacific Standard Time|UTC+10:00 | Tasmania Standard Time|UTC+10:00 | Yakutsk Standard Time|UTC+10:00 |
Central Pacific Standard Time|UTC+11:00 | Vladivostok Standard Time|UTC+11:00 | New Zealand Standard Time|UTC+12:00 |
UTC+12|UTC+12:00 | Fiji Standard Time|UTC+12:00 | Magadan Standard Time|UTC+12:00 |
时区表的用法
假如我想模拟2个时区来写测试case,那么我们可以这样做:
TimeZoneInfo UTC_8 = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");//-8 TimeZoneInfo UTC_4 = TimeZoneInfo.Local; DateTime dt_4 = new DateTime(2013, 5, 8, 7, 0, 0); //-4 DateTime dt_8 = TimeZoneInfo.ConvertTime(dt_4, UTC_8);
备注
在这张时区表中,用符号'|'对时区的标准名称和时区对应UTC时间的偏移量值进行了分割,这样做是为了方便检索。在实际使用过程中,我们仅仅需要时区的标准名称(可以参考本文的小例子)。