UTC转换为中欧标准时间的时间是提前2小时而不是1小时 [英] UTC converted to Central Europe Standard Time is 2 hours in front not 1

查看:55
本文介绍了UTC转换为中欧标准时间的时间是提前2小时而不是1小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图了解我的约会日期有误的原因:

I'm trying to understand why my date is wrong:

DateTime databaseUtcTime = new DateTime(2016, 8, 15, 10, 20, 0, DateTimeKind.Utc);
var timeZone = TimeZoneInfo.FindSystemTimeZoneById("Central Europe Standard Time");
var testDateTime = TimeZoneInfo.ConvertTimeFromUtc(databaseUtcTime, timeZone);

testDateTime 输出 2016年8月15日12:20:00 而不是 2016年8月15日11:20:00 为什么会这样?应该不是从UTC向前1小时,而不是2小时?

testDateTime outputs 15/08/2016 12:20:00 rather than 15/08/2016 11:20:00 why is this? Shouldn't it be 1 hour forward from UTC, not 2 ?

编辑----

感谢乔恩·斯基特,

如果这可以帮助任何人,我将使用:

If this helps anyone, i resorted to using:

if(testDateTime.IsDaylightSavingTime())
{
    testDateTime = testDateTime.AddHours(-1);
}

即使您不了解上下文,这也可能有助于了解在按时运行某些显式测试时如何摆脱夏时制.

Albeit you not knowing the context, this could be helpful to know how to get rid of daylight saving time when running certain explicit testing on time.

推荐答案

ID为中欧标准时间"的时区只是中欧使用的时区……它不是真正地平均标准时间.

The time zone with an ID of "Central Europe Standard Time" is just the one used by central Europe... it doesn't really mean standard time.

由于中欧目前正在观察夏令时,因此偏移量的确是UTC + 2.

As central Europe is observing daylight savings at the moment, the offset really is UTC+2.

很不幸,Windows时区中使用的ID会引起这种误导...但是 TimeZoneInfo 实现本身是正确的.

It's very unfortunate that the IDs used in Windows time zones are misleading like this... but the TimeZoneInfo implementation itself is correct.

(这不是Windows时区名称的全部问题...请参见

(This isn't all that's wrong with Windows time zone names... see Matt Johnson's post on the matter for more...)

这篇关于UTC转换为中欧标准时间的时间是提前2小时而不是1小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆