UTC 转换为中欧标准时间是前面 2 小时而不是 1

Jim*_*988 2 c# timezone datetime

我试图理解为什么我的约会是错误的:

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);
Run Code Online (Sandbox Code Playgroud)

testDateTime 输出15/08/2016 12:20:00而不是15/08/2016 11:20:00 为什么会这样?UTC 不应该提前 1 小时,而不是 2 小时吗?

编辑 - -

谢谢乔恩·斯基特,

如果这对任何人有帮助,我就使用:

if(testDateTime.IsDaylightSavingTime())
{
    testDateTime = testDateTime.AddHours(-1);
}
Run Code Online (Sandbox Code Playgroud)

尽管您不知道上下文,但这可能有助于了解在按时运行某些显式测试时如何摆脱夏令时。

Jon*_*eet 5

ID为“中欧标准时间”的时区只是中欧使用的时区……并不是真正的标准时间。

由于中欧目前正在遵守夏令时,因此偏移量确实是 UTC+2。

非常不幸的是,Windows 时区中使用的 ID 像这样具有误导性……但TimeZoneInfo实现本身是正确的。

(这并不是 Windows 时区名称的全部错误……有关更多信息,请参阅Matt Johnson 的帖子……)

  • Jon Skeet,Jo(h)n Cena 的程序员版本。 (2认同)