c# - 转换为中欧标准时间的 UTC 提前 2 小时而不是 1 小时

标签 c# datetime timezone

我想了解为什么我的日期是错误的:

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 输出 15/08/2016 12:20:00 而不是 15/08/2016 11:20:00 这是为什么? 不应该比 UTC 早 1 小时,而不是 2 小时吗?

编辑----

谢谢乔恩斯基特,

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

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

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

最佳答案

ID 为“中欧标准时间”的时区只是中欧使用的时区...它真的不是标准时间。

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

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

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

关于c# - 转换为中欧标准时间的 UTC 提前 2 小时而不是 1 小时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38955650/

相关文章:

lua - 如何更新lua中的时间以反射(reflect)执行期间系统时区的变化?

c# - MVVM模式是否适合此应用程序的要求?

c# - 使用线程时检查条件失败

java - 如何比较实例化的 DateTime 对象?

c - linux 将时间(针对不同的时区)转换为 UTC

javascript - 带时区的 node-cron

c# - 将 .aspx 转换为 .ascx 时的验证

c# - 如何在 .Net Core 的 AuthorizeAttribute 类中访问 appsetting.json 参数

python - 比较 Python 中的两个 UTC 时间戳

.net - 如何在 01-24 而不是 00-23 中表示 .NET DateTime 24 小时格式?