zoukankan      html  css  js  c++  java
  • 时区和夏令时

    一个项目在西欧,之前取时间简单用DateTime.UtcNow.AddHours(1); //西欧都是在第1时区. 

    3月份之前都正确,但欧盟国家和瑞士都是从3月最后一个星期日到10月最后一个星期日实行夏令时。在格林尼治时间三月最后一个星期日的2:00欧盟国家同时进行时间更改。

    4月份之后就差了一个小时,也就是说DateTime.UtcNow取得的时间是不带夏令时的。

    所以要用TimeZoneInfo类来解决时区问题。下面的代码就可以对比差别了。

                DateTime dtNow = DateTime.UtcNow.AddHours(1); //西欧
                Console.WriteLine("DateTime.UtcNow=" + DateTime.UtcNow.ToString());
                Console.WriteLine("dtNow=" + dtNow.ToString());
    
                DateTime dt = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(
                    DateTime.UtcNow,"UTC","W. Europe Standard Time");
                Console.WriteLine("TimeZone dt =" + dt.ToString());
    

    TimeZoneId怎样知道呢?

    foreach (TimeZoneInfo timeZoneInfo in TimeZoneInfo.GetSystemTimeZones())
    {
    
        Console.WriteLine(timeZoneInfo.DisplayName);
        Console.WriteLine(timeZoneInfo.Id);
    
    }
    

    结果如下:

    (UTC-12:00) 国际日期变更线以西 
    Dateline Standard Time

    (UTC-11:00) 国际标准时间-11 
    UTC-11

    (UTC-10:00) 夏威夷 
    Hawaiian Standard Time

    (UTC-09:00) 阿拉斯加 
    Alaskan Standard Time

    (UTC-08:00) 下加利福尼亚 
    Pacific Standard Time (Mexico)

    (UTC-08:00) 太平洋时间 (美国和加拿大) 
    Pacific Standard Time

    (UTC-07:00) 亚历桑那 
    US Mountain Standard Time

    (UTC-07:00) 山区时间 (美国和加拿大) 
    Mountain Standard Time

    (UTC-07:00) 齐骅华,拉帕兹,马札特兰 
    Mountain Standard Time (Mexico)

    (UTC-06: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-05:00) 印第安纳 (东部) 
    US Eastern Standard Time

    (UTC-05:00) 东部时间 (美国和加拿大) 
    Eastern Standard Time

    (UTC-05:00) 波哥大,利马,基多 
    SA Pacific Standard Time

    (UTC-04:30) 卡拉卡斯 
    Venezuela Standard Time

    (UTC-04:00) 亚松森 
    Paraguay Standard Time

    (UTC-04:00) 佐治敦,拉帕兹,玛瑙斯,圣胡安 
    SA Western Standard Time

    (UTC-04:00) 古雅巴 
    Central Brazilian Standard Time

    (UTC-04:00) 大西洋时间 (加拿大) 
    Atlantic Standard Time

    (UTC-04:00) 圣地亚哥 
    Pacific SA Standard Time

    (UTC-03:30) 纽芬兰 
    Newfoundland Standard Time

    (UTC-03:00) 巴西利亚 
    E. South America Standard Time

    (UTC-03:00) 布宜诺斯艾利斯 
    Argentina Standard Time

    (UTC-03:00) 格陵兰 
    Greenland Standard Time

    (UTC-03:00) 蒙特维多 
    Montevideo Standard Time

    (UTC-03:00) 萨尔瓦多 
    Bahia Standard Time

    (UTC-03:00) 开云,福塔力沙 
    SA Eastern Standard Time

    (UTC-02:00) 国际标准时间-02 
    UTC-02

    (UTC-02:00) 大西洋中部 
    Mid-Atlantic Standard Time

    (UTC-01:00) 亚速尔群岛 
    Azores Standard Time

    (UTC-01:00) 维德角群岛 
    Cape Verde Standard Time

    (UTC) 卡萨布兰卡 
    Morocco Standard Time

    (UTC) 国际标准时间 
    UTC

    (UTC) 蒙罗维亚,雷克雅维克 
    Greenwich Standard Time

    (UTC) 都柏林,爱丁堡,里斯本,伦敦 
    GMT Standard Time

    (UTC+01:00) 中西非 
    W. Central Africa Standard Time

    (UTC+01:00) 塞拉耶佛,斯高彼亚,华沙,札格雷布 
    Central European Standard Time

    (UTC+01:00) 布鲁塞尔,哥本哈根,马德里,巴黎 
    Romance Standard Time

    (UTC+01:00) 温吐克 
    Namibia Standard Time

    (UTC+01:00) 贝尔格勒,布拉提斯拉瓦,布达佩斯,卢布亚纳,布拉格 
    Central Europe Standard Time

    (UTC+01:00) 阿姆斯特丹,柏林,伯恩,罗马,斯德哥尔摩,维也纳 
    W. Europe Standard Time

    (UTC+02:00) 伊斯坦堡 
    Turkey Standard Time

    (UTC+02:00) 哈拉雷,皮托里 
    South Africa Standard Time

    (UTC+02:00) 大马士革 
    Syria Standard Time

    (UTC+02:00) 东欧 
    E. Europe Standard Time

    (UTC+02:00) 耶路撒冷 
    Israel Standard Time

    (UTC+02:00) 贝鲁特 
    Middle East Standard Time

    (UTC+02:00) 赫尔辛基,凯耶夫,里加,苏非亚,塔林,维尔纽斯 
    FLE Standard Time

    (UTC+02:00) 开罗 
    Egypt Standard Time

    (UTC+02:00) 雅典,布加勒斯特 
    GTB Standard Time

    (UTC+03:00) 卡里宁格勒,明斯克 
    Kaliningrad Standard Time

    (UTC+03:00) 奈洛比 
    E. Africa Standard Time

    (UTC+03:00) 安曼 
    Jordan Standard Time

    (UTC+03:00) 巴格达 
    Arabic Standard Time

    (UTC+03:00) 科威特,利雅德 
    Arab Standard Time

    (UTC+03:30) 德黑兰 
    Iran Standard Time

    (UTC+04:00) 巴库 
    Azerbaijan Standard Time

    (UTC+04:00) 第比利斯 
    Georgian Standard Time

    (UTC+04:00) 莫斯科,圣彼得堡,伏尔加格勒 
    Russian Standard Time

    (UTC+04:00) 叶里温 
    Caucasus Standard Time

    (UTC+04:00) 路易斯港 
    Mauritius Standard Time

    (UTC+04:00) 阿布达比,马斯喀特 
    Arabian Standard Time

    (UTC+04:30) 喀布尔 
    Afghanistan Standard Time

    (UTC+05:00) 伊斯兰马巴德,克洛奇 
    Pakistan Standard Time

    (UTC+05:00) 塔什干 
    West Asia Standard Time

    (UTC+05:30) 斯里哈亚华登尼普拉 
    Sri Lanka Standard Time

    (UTC+05:30) 辰内,加尔各答,孟拜,新德里 
    India Standard Time

    (UTC+05:45) 加德满都 
    Nepal Standard Time

    (UTC+06:00) 伊卡特林堡 
    Ekaterinburg Standard Time

    (UTC+06:00) 达卡 
    Bangladesh Standard Time

    (UTC+06:00) 阿斯坦纳 
    Central Asia Standard Time

    (UTC+06:30) 仰光 
    Myanmar Standard Time

    (UTC+07:00) 曼谷,河内,雅加达 
    SE Asia Standard Time

    (UTC+07:00) 诺曼斯比尔斯科 
    N. Central Asia Standard Time

    (UTC+08:00) 伯斯 
    W. Australia Standard Time

    (UTC+08:00) 克拉斯诺亚尔斯克 
    North Asia Standard Time

    (UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐 
    China Standard Time

    (UTC+08:00) 台北 
    Taipei Standard Time

    (UTC+08:00) 吉隆坡,新加坡 
    Singapore Standard Time

    (UTC+08:00) 库伦 
    Ulaanbaatar Standard Time

    (UTC+09:00) 伊尔库次克 
    North Asia East Standard Time

    (UTC+09:00) 大阪,北海道,东京 
    Tokyo Standard Time

    (UTC+09:00) 首尔 
    Korea Standard Time

    (UTC+09:30) 爱德兰 
    Cen. Australia Standard Time

    (UTC+09:30) 达尔文 
    AUS Central Standard Time

    (UTC+10:00) 亚库兹克 
    Yakutsk Standard Time

    (UTC+10:00) 堪培拉,墨尔本,雪梨 
    AUS Eastern Standard Time

    (UTC+10:00) 布里斯本 
    E. Australia Standard Time

    (UTC+10:00) 关岛,穆尔斯贝港 
    West Pacific Standard Time

    (UTC+10:00) 霍巴特 
    Tasmania Standard Time

    (UTC+11:00) 海参威 
    Vladivostok Standard Time

    (UTC+11:00) 索罗门群岛,新喀里多尼亚群岛 
    Central Pacific Standard Time

    (UTC+12:00) 国际标准时间+12 
    UTC+12

    (UTC+12:00) 奥克兰,威灵顿 
    New Zealand Standard Time

    (UTC+12:00) 彼得保罗夫斯克-堪察加斯克 - 已过时 
    Kamchatka Standard Time

    (UTC+12:00) 斐济 
    Fiji Standard Time

    (UTC+12:00) 马加丹 
    Magadan Standard Time

    (UTC+13:00) 努瓜娄发 
    Tonga Standard Time

    (UTC+13:00) 萨摩亚 
    Samoa Standard Time

  • 相关阅读:
    POJ2126——Prime Path(BFS)
    POJ3020——Antenna Placement(二分图的最大匹配)
    POJ1019——Number Sequence(大数处理)
    CodeForces484A——Bits(贪心算法)
    CodeForces485B——Valuable Resources(水题)
    CodeForces485A——Factory(抽屉原理)
    HDU5092——Seam Carving(动态规划+回溯)(2014上海邀请赛重现)
    cache和buffer区别
    https页面证书验证、加密过程简介
    主要的开源镜像站点资源
  • 原文地址:https://www.cnblogs.com/zitjubiz/p/4413344.html
Copyright © 2011-2022 走看看